mobileandwirelesssystemsprogrammingridene.youssef.free.fr/courses/android/appfundamentals-android.pdf ·...

28
Introduction Application Components Activating components Developping apps Mobile and Wireless Systems Programming Application Fundamentals Youssef RIDENE : [email protected] Mobile and Wireless Systems Programming

Upload: others

Post on 16-Oct-2020

5 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: MobileandWirelessSystemsProgrammingridene.youssef.free.fr/courses/android/AppFundamentals-Android.pdf · Introduction ApplicationComponents Activatingcomponents Developpingapps MobileandWirelessSystemsProgramming

IntroductionApplication ComponentsActivating components

Developping apps

Mobile and Wireless Systems Programming

Application Fundamentals

Youssef RIDENE : [email protected] Mobile and Wireless Systems Programming

Page 2: MobileandWirelessSystemsProgrammingridene.youssef.free.fr/courses/android/AppFundamentals-Android.pdf · Introduction ApplicationComponents Activatingcomponents Developpingapps MobileandWirelessSystemsProgramming

IntroductionApplication ComponentsActivating components

Developping apps

Java programming languageAndroid package : .apkDalvik VM executes files in the Dalvik Executable (.dex)format1 .apk = 1 application1 application = 1 Linux process1 application = 1 virtual machine

Youssef RIDENE : [email protected] Mobile and Wireless Systems Programming

Page 3: MobileandWirelessSystemsProgrammingridene.youssef.free.fr/courses/android/AppFundamentals-Android.pdf · Introduction ApplicationComponents Activatingcomponents Developpingapps MobileandWirelessSystemsProgramming

IntroductionApplication ComponentsActivating components

Developping apps

ActivitiesServicesBroadcast receiversContent providers

A visual user interfaceImplemented as a subclass of android.app.ActivityMany activities in the same projectEach activity is independent of the others1 Activity = 1 window

Youssef RIDENE : [email protected] Mobile and Wireless Systems Programming

Page 4: MobileandWirelessSystemsProgrammingridene.youssef.free.fr/courses/android/AppFundamentals-Android.pdf · Introduction ApplicationComponents Activatingcomponents Developpingapps MobileandWirelessSystemsProgramming

IntroductionApplication ComponentsActivating components

Developping apps

ActivitiesServicesBroadcast receiversContent providers

No visual UIRuns in the background for an indefinite period of timeExtends android.app.Service

Youssef RIDENE : [email protected] Mobile and Wireless Systems Programming

Page 5: MobileandWirelessSystemsProgrammingridene.youssef.free.fr/courses/android/AppFundamentals-Android.pdf · Introduction ApplicationComponents Activatingcomponents Developpingapps MobileandWirelessSystemsProgramming

IntroductionApplication ComponentsActivating components

Developping apps

ActivitiesServicesBroadcast receiversContent providers

Receive and react to broadcast announcementsNo visual UIExtends android.content.BroadcastReceiverFor example : announcements that the battery is low, that apicture has been taken, or that the user changed a languagepreference. . .

Youssef RIDENE : [email protected] Mobile and Wireless Systems Programming

Page 6: MobileandWirelessSystemsProgrammingridene.youssef.free.fr/courses/android/AppFundamentals-Android.pdf · Introduction ApplicationComponents Activatingcomponents Developpingapps MobileandWirelessSystemsProgramming

IntroductionApplication ComponentsActivating components

Developping apps

ActivitiesServicesBroadcast receiversContent providers

Makes a specific set of the application’s data available to otherapplicationsData can be stored in the file system, in an SQLite database. . .Extends android.content.ContentProvider

Youssef RIDENE : [email protected] Mobile and Wireless Systems Programming

Page 7: MobileandWirelessSystemsProgrammingridene.youssef.free.fr/courses/android/AppFundamentals-Android.pdf · Introduction ApplicationComponents Activatingcomponents Developpingapps MobileandWirelessSystemsProgramming

IntroductionApplication ComponentsActivating components

Developping apps

Intent

An abstract description of an operation to be performedCan be caused with :

startActivitybroadcastIntentstartService or bindService

Youssef RIDENE : [email protected] Mobile and Wireless Systems Programming

Page 8: MobileandWirelessSystemsProgrammingridene.youssef.free.fr/courses/android/AppFundamentals-Android.pdf · Introduction ApplicationComponents Activatingcomponents Developpingapps MobileandWirelessSystemsProgramming

IntroductionApplication ComponentsActivating components

Developping apps

Intent

Intent()Intent(Intent o)Intent(String action)Intent(String action, Uri uri)Intent(Context packageContext, Class< ?> cls)Intent(String action, Uri uri, Context packageContext,Class< ?> cls)

Intent myIntent = new Intent(CurrentActivity.this,NextActivity.class) ;CurrentActivity.this.startActivity(myIntent) ;

Youssef RIDENE : [email protected] Mobile and Wireless Systems Programming

Page 9: MobileandWirelessSystemsProgrammingridene.youssef.free.fr/courses/android/AppFundamentals-Android.pdf · Introduction ApplicationComponents Activatingcomponents Developpingapps MobileandWirelessSystemsProgramming

IntroductionApplication ComponentsActivating components

Developping apps

Intent

Action :ACTION_VIEWACTION_MAINACTION_EDITACTION_DIAL. . .

Uri :tel :123http ://www.uni-pau.frcontent ://contacts/people/1. . .

Intent viewIntent = new Intent("android.intent.action.VIEW",Uri.parse("http ://www.univ-pau.fr")) ;startActivity(viewIntent) ;

Youssef RIDENE : [email protected] Mobile and Wireless Systems Programming

Page 10: MobileandWirelessSystemsProgrammingridene.youssef.free.fr/courses/android/AppFundamentals-Android.pdf · Introduction ApplicationComponents Activatingcomponents Developpingapps MobileandWirelessSystemsProgramming

IntroductionApplication ComponentsActivating components

Developping apps

ADTApp structureResourcesThe Manifest fileActivityUser InterfaceUser interaction

Project wizard

Youssef RIDENE : [email protected] Mobile and Wireless Systems Programming

Page 11: MobileandWirelessSystemsProgrammingridene.youssef.free.fr/courses/android/AppFundamentals-Android.pdf · Introduction ApplicationComponents Activatingcomponents Developpingapps MobileandWirelessSystemsProgramming

IntroductionApplication ComponentsActivating components

Developping apps

ADTApp structureResourcesThe Manifest fileActivityUser InterfaceUser interaction

Youssef RIDENE : [email protected] Mobile and Wireless Systems Programming

Page 12: MobileandWirelessSystemsProgrammingridene.youssef.free.fr/courses/android/AppFundamentals-Android.pdf · Introduction ApplicationComponents Activatingcomponents Developpingapps MobileandWirelessSystemsProgramming

IntroductionApplication ComponentsActivating components

Developping apps

ADTApp structureResourcesThe Manifest fileActivityUser InterfaceUser interaction

Resources

Youssef RIDENE : [email protected] Mobile and Wireless Systems Programming

Page 13: MobileandWirelessSystemsProgrammingridene.youssef.free.fr/courses/android/AppFundamentals-Android.pdf · Introduction ApplicationComponents Activatingcomponents Developpingapps MobileandWirelessSystemsProgramming

IntroductionApplication ComponentsActivating components

Developping apps

ADTApp structureResourcesThe Manifest fileActivityUser InterfaceUser interaction

Resources

asset (AssetManager)Instantiate layout elements at runtime

Button myButton = (Button) findViewById(R.id.my_button) ;TextView myTextView = (TextView)findViewById(R.id.my_textView) ;

Youssef RIDENE : [email protected] Mobile and Wireless Systems Programming

Page 14: MobileandWirelessSystemsProgrammingridene.youssef.free.fr/courses/android/AppFundamentals-Android.pdf · Introduction ApplicationComponents Activatingcomponents Developpingapps MobileandWirelessSystemsProgramming

IntroductionApplication ComponentsActivating components

Developping apps

ADTApp structureResourcesThe Manifest fileActivityUser InterfaceUser interaction

AndroidManifest.xmlContain all the application components (Activity, Persmissions,SDK version. . . )

<a c t i v i t y> . . .</ a c t i v i t y><s e r v i c e> . . .</ s e r v i c e><r e c e i v e r> . . .</ r e c e i v e r><p r o v i d e r> . . .</ p r o v i d e r>

Youssef RIDENE : [email protected] Mobile and Wireless Systems Programming

Page 15: MobileandWirelessSystemsProgrammingridene.youssef.free.fr/courses/android/AppFundamentals-Android.pdf · Introduction ApplicationComponents Activatingcomponents Developpingapps MobileandWirelessSystemsProgramming

IntroductionApplication ComponentsActivating components

Developping apps

ADTApp structureResourcesThe Manifest fileActivityUser InterfaceUser interaction

AndroidManifest.xml

<? xml v e r s i o n=" 1 .0 " encod ing=" ut f−8"?><man i f e s t . . .>

<a p p l i c a t i o n . . .><a c t i v i t y andro id :name="com . uppa .m2 . F i r s t A c t i v i t y "

a n d r o i d : i c o n="@drawable / i c on . png"a n d r o i d : l a b e l=" @ s t r i n g / f i r s t L a b e l ". . .>

</ a c t i v i t y>. . .

</ a p p l i c a t i o n></man i f e s t>

Youssef RIDENE : [email protected] Mobile and Wireless Systems Programming

Page 16: MobileandWirelessSystemsProgrammingridene.youssef.free.fr/courses/android/AppFundamentals-Android.pdf · Introduction ApplicationComponents Activatingcomponents Developpingapps MobileandWirelessSystemsProgramming

IntroductionApplication ComponentsActivating components

Developping apps

ADTApp structureResourcesThe Manifest fileActivityUser InterfaceUser interaction

Activity

Android Activity is a equivalent to a MIDP MIDlet but !GUI and User inuptsOne Activity for each screenLifecycle :

void onCreate(Bundle savedInstanceState)void onStart()void onRestart()void onResume()void onPause()void onStop()void onDestroy()

Youssef RIDENE : [email protected] Mobile and Wireless Systems Programming

Page 17: MobileandWirelessSystemsProgrammingridene.youssef.free.fr/courses/android/AppFundamentals-Android.pdf · Introduction ApplicationComponents Activatingcomponents Developpingapps MobileandWirelessSystemsProgramming
Page 18: MobileandWirelessSystemsProgrammingridene.youssef.free.fr/courses/android/AppFundamentals-Android.pdf · Introduction ApplicationComponents Activatingcomponents Developpingapps MobileandWirelessSystemsProgramming

IntroductionApplication ComponentsActivating components

Developping apps

ADTApp structureResourcesThe Manifest fileActivityUser InterfaceUser interaction

Activity

package com . uppa . h e l l o a n d r o i d ;

import and ro i d . app . A c t i v i t y ;import and ro i d . os . Bundle ;

pub l i c c l a s s He l l oAnd ro i d extends A c t i v i t y {/∗∗ Ca l l e d when the a c t i v i t y i s f i r s t c r e a t e d . ∗/@Over r idepub l i c void onCreate ( Bundle s a v e d I n s t a n c e S t a t e ) {

super . onCreate ( s a v e d I n s t a n c e S t a t e ) ;s e tContentV iew (R . l a y o u t . main ) ;

}}

Youssef RIDENE : [email protected] Mobile and Wireless Systems Programming

Page 19: MobileandWirelessSystemsProgrammingridene.youssef.free.fr/courses/android/AppFundamentals-Android.pdf · Introduction ApplicationComponents Activatingcomponents Developpingapps MobileandWirelessSystemsProgramming

IntroductionApplication ComponentsActivating components

Developping apps

ADTApp structureResourcesThe Manifest fileActivityUser InterfaceUser interaction

UI

Declare UI elements in XML (Wysiwyg editor)<? xml v e r s i o n=" 1 .0 " encod ing=" ut f−8"?><L inea rLayou t xm l n s : a nd r o i d=" h t t p : // schemas . and r o i d . com/apk/ r e s / and ro i d "

and r o i d : l a y ou t_w id t h=" f i l l _ p a r e n t "a nd r o i d : l a y o u t_he i g h t=" f i l l _ p a r e n t "a n d r o i d : o r i e n t a t i o n=" v e r t i c a l " >

<TextView a n d r o i d : i d="@+i d /my_textView"and r o i d : l a y ou t_w id t h="wrap_content "a nd r o i d : l a y o u t_he i g h t="wrap_content "a n d r o i d : t e x t="He l l o , ␣ I ␣am␣a␣TextView" />

<Button a n d r o i d : i d="@+i d /my_button"and r o i d : l a y ou t_w id t h="wrap_content "a nd r o i d : l a y o u t_he i g h t="wrap_content "a n d r o i d : t e x t="He l l o , ␣ I ␣am␣a␣Button" />

</ L inea rLayou t>

Youssef RIDENE : [email protected] Mobile and Wireless Systems Programming

Page 20: MobileandWirelessSystemsProgrammingridene.youssef.free.fr/courses/android/AppFundamentals-Android.pdf · Introduction ApplicationComponents Activatingcomponents Developpingapps MobileandWirelessSystemsProgramming

IntroductionApplication ComponentsActivating components

Developping apps

ADTApp structureResourcesThe Manifest fileActivityUser InterfaceUser interaction

UI Builder

Youssef RIDENE : [email protected] Mobile and Wireless Systems Programming

Page 21: MobileandWirelessSystemsProgrammingridene.youssef.free.fr/courses/android/AppFundamentals-Android.pdf · Introduction ApplicationComponents Activatingcomponents Developpingapps MobileandWirelessSystemsProgramming

IntroductionApplication ComponentsActivating components

Developping apps

ADTApp structureResourcesThe Manifest fileActivityUser InterfaceUser interaction

Components

LayoutsWidgetsDialogMenus

Youssef RIDENE : [email protected] Mobile and Wireless Systems Programming

Page 22: MobileandWirelessSystemsProgrammingridene.youssef.free.fr/courses/android/AppFundamentals-Android.pdf · Introduction ApplicationComponents Activatingcomponents Developpingapps MobileandWirelessSystemsProgramming

IntroductionApplication ComponentsActivating components

Developping apps

ADTApp structureResourcesThe Manifest fileActivityUser InterfaceUser interaction

Layout

Youssef RIDENE : [email protected] Mobile and Wireless Systems Programming

Page 23: MobileandWirelessSystemsProgrammingridene.youssef.free.fr/courses/android/AppFundamentals-Android.pdf · Introduction ApplicationComponents Activatingcomponents Developpingapps MobileandWirelessSystemsProgramming

IntroductionApplication ComponentsActivating components

Developping apps

ADTApp structureResourcesThe Manifest fileActivityUser InterfaceUser interaction

Widgets

Youssef RIDENE : [email protected] Mobile and Wireless Systems Programming

Page 24: MobileandWirelessSystemsProgrammingridene.youssef.free.fr/courses/android/AppFundamentals-Android.pdf · Introduction ApplicationComponents Activatingcomponents Developpingapps MobileandWirelessSystemsProgramming

IntroductionApplication ComponentsActivating components

Developping apps

ADTApp structureResourcesThe Manifest fileActivityUser InterfaceUser interaction

AlertDialog

Youssef RIDENE : [email protected] Mobile and Wireless Systems Programming

Page 25: MobileandWirelessSystemsProgrammingridene.youssef.free.fr/courses/android/AppFundamentals-Android.pdf · Introduction ApplicationComponents Activatingcomponents Developpingapps MobileandWirelessSystemsProgramming

IntroductionApplication ComponentsActivating components

Developping apps

ADTApp structureResourcesThe Manifest fileActivityUser InterfaceUser interaction

ProgressDialog

Youssef RIDENE : [email protected] Mobile and Wireless Systems Programming

Page 26: MobileandWirelessSystemsProgrammingridene.youssef.free.fr/courses/android/AppFundamentals-Android.pdf · Introduction ApplicationComponents Activatingcomponents Developpingapps MobileandWirelessSystemsProgramming

IntroductionApplication ComponentsActivating components

Developping apps

ADTApp structureResourcesThe Manifest fileActivityUser InterfaceUser interaction

Notification

Youssef RIDENE : [email protected] Mobile and Wireless Systems Programming

Page 27: MobileandWirelessSystemsProgrammingridene.youssef.free.fr/courses/android/AppFundamentals-Android.pdf · Introduction ApplicationComponents Activatingcomponents Developpingapps MobileandWirelessSystemsProgramming

IntroductionApplication ComponentsActivating components

Developping apps

ADTApp structureResourcesThe Manifest fileActivityUser InterfaceUser interaction

Toast

Youssef RIDENE : [email protected] Mobile and Wireless Systems Programming

Page 28: MobileandWirelessSystemsProgrammingridene.youssef.free.fr/courses/android/AppFundamentals-Android.pdf · Introduction ApplicationComponents Activatingcomponents Developpingapps MobileandWirelessSystemsProgramming

IntroductionApplication ComponentsActivating components

Developping apps

ADTApp structureResourcesThe Manifest fileActivityUser InterfaceUser interaction

User interaction

KeyPadClickListener (onClick(View))KeyListener (onKeyUp(KeyEvent), onKeyDown(KeyEvent))

TouchScreenTouchListener (onTouchEvent(MotionEvent))

Youssef RIDENE : [email protected] Mobile and Wireless Systems Programming