Introduction Application Components Activating components Developping apps
Mobile and Wireless Systems Programming Application Fundamentals
Youssef RIDENE :
[email protected]
Mobile and Wireless Systems Programming
Introduction Application Components Activating components Developping apps
Java programming language Android package : .apk Dalvik VM executes files in the Dalvik Executable (.dex) format 1 .apk = 1 application 1 application = 1 Linux process 1 application = 1 virtual machine
Youssef RIDENE :
[email protected]
Mobile and Wireless Systems Programming
Introduction Application Components Activating components Developping apps
Activities Services Broadcast receivers Content providers
A visual user interface Implemented as a subclass of android.app.Activity Many activities in the same project Each activity is independent of the others 1 Activity = 1 window
Youssef RIDENE :
[email protected]
Mobile and Wireless Systems Programming
Introduction Application Components Activating components Developping apps
Activities Services Broadcast receivers Content providers
No visual UI Runs in the background for an indefinite period of time Extends android.app.Service
Youssef RIDENE :
[email protected]
Mobile and Wireless Systems Programming
Introduction Application Components Activating components Developping apps
Activities Services Broadcast receivers Content providers
Receive and react to broadcast announcements No visual UI Extends android.content.BroadcastReceiver For example : announcements that the battery is low, that a picture has been taken, or that the user changed a language preference. . .
Youssef RIDENE :
[email protected]
Mobile and Wireless Systems Programming
Introduction Application Components Activating components Developping apps
Activities Services Broadcast receivers Content providers
Makes a specific set of the application’s data available to other applications Data can be stored in the file system, in an SQLite database. . . Extends android.content.ContentProvider
Youssef RIDENE :
[email protected]
Mobile and Wireless Systems Programming
Introduction Application Components Activating components Developping apps
Intent
An abstract description of an operation to be performed Can be caused with : startActivity broadcastIntent startService or bindService
Youssef RIDENE :
[email protected]
Mobile and Wireless Systems Programming
Introduction Application Components Activating 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
Introduction Application Components Activating components Developping apps
Intent Action : ACTION_VIEW ACTION_MAIN ACTION_EDIT ACTION_DIAL ...
Uri : tel :123 http ://www.uni-pau.fr content ://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
Introduction Application Components Activating components Developping apps
ADT App structure Resources The Manifest file Activity User Interface User interaction
Project wizard
Youssef RIDENE :
[email protected]
Mobile and Wireless Systems Programming
Introduction Application Components Activating components Developping apps
Youssef RIDENE :
[email protected]
ADT App structure Resources The Manifest file Activity User Interface User interaction
Mobile and Wireless Systems Programming
Introduction Application Components Activating components Developping apps
ADT App structure Resources The Manifest file Activity User Interface User interaction
Resources
Youssef RIDENE :
[email protected]
Mobile and Wireless Systems Programming
Introduction Application Components Activating components Developping apps
ADT App structure Resources The Manifest file Activity User Interface User 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
Introduction Application Components Activating components Developping apps
ADT App structure Resources The Manifest file Activity User Interface User interaction
AndroidManifest.xml Contain all the application components (Activity, Persmissions, SDK version. . . ) < a c t i v i t y> . . . < s e r v i c e> . . . < r e c e i v e r> . . . < p r o v i d e r> . . .
Youssef RIDENE :
[email protected]
Mobile and Wireless Systems Programming
Introduction Application Components Activating components Developping apps
ADT App structure Resources The Manifest file Activity User Interface User interaction
AndroidManifest.xml
< a c t i v i t y a n d r o i d : n a m e="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=" @ d r a w a b l e / i c o n . 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 " . . .> ...
Youssef RIDENE : [email protected]
Mobile and Wireless Systems Programming
Introduction Application Components Activating components Developping apps
ADT App structure Resources The Manifest file Activity User Interface User interaction
Activity Android Activity is a equivalent to a MIDP MIDlet but ! GUI and User inupts One Activity for each screen Lifecycle : void void void void void void void
onCreate(Bundle savedInstanceState) onStart() onRestart() onResume() onPause() onStop() onDestroy()
Youssef RIDENE : [email protected]
Mobile and Wireless Systems Programming
Introduction Application Components Activating components Developping apps
ADT App structure Resources The Manifest file Activity User Interface User interaction
Activity package com . uppa . h e l l o a n d r o i d ; import a n d r o i d . app . A c t i v i t y ; import a n d r o i d . o s . B u n d l e ;
p u b l i c c l a s s H e l l o A n d r o i d extends A c t i v i t y { /∗ ∗ C a l l e d when t h e a c t i v i t y i s f i r s t c r e a t e d . ∗ @Override public void onCreate ( Bundle s a v e d I n s t a n c e S t a t e ) super . o n C r e a t e ( s a v e d I n s t a n c e S t a t e ) ; s e t C o n t e n t V i e w (R . l a y o u t . main ) ; } } Youssef RIDENE : [email protected]
Mobile and Wireless Systems Programming
Introduction Application Components Activating components Developping apps
ADT App structure Resources The Manifest file Activity User Interface User interaction
UI Declare UI elements in XML (Wysiwyg editor)
Youssef RIDENE : [email protected]
Mobile and Wireless Systems Programming
Introduction Application Components Activating components Developping apps
ADT App structure Resources The Manifest file Activity User Interface User interaction
UI Builder
Youssef RIDENE : [email protected]
Mobile and Wireless Systems Programming
Introduction Application Components Activating components Developping apps
ADT App structure Resources The Manifest file Activity User Interface User interaction
Components
Layouts Widgets Dialog Menus
Youssef RIDENE : [email protected]
Mobile and Wireless Systems Programming
Introduction Application Components Activating components Developping apps
ADT App structure Resources The Manifest file Activity User Interface User interaction
Layout
Youssef RIDENE : [email protected]
Mobile and Wireless Systems Programming
Introduction Application Components Activating components Developping apps
ADT App structure Resources The Manifest file Activity User Interface User interaction
Widgets
Youssef RIDENE : [email protected]
Mobile and Wireless Systems Programming
Introduction Application Components Activating components Developping apps
ADT App structure Resources The Manifest file Activity User Interface User interaction
AlertDialog
Youssef RIDENE : [email protected]
Mobile and Wireless Systems Programming
Introduction Application Components Activating components Developping apps
ADT App structure Resources The Manifest file Activity User Interface User interaction
ProgressDialog
Youssef RIDENE : [email protected]
Mobile and Wireless Systems Programming
Introduction Application Components Activating components Developping apps
ADT App structure Resources The Manifest file Activity User Interface User interaction
Notification
Youssef RIDENE : [email protected]
Mobile and Wireless Systems Programming
Introduction Application Components Activating components Developping apps
ADT App structure Resources The Manifest file Activity User Interface User interaction
Toast
Youssef RIDENE : [email protected]
Mobile and Wireless Systems Programming
Introduction Application Components Activating components Developping apps
ADT App structure Resources The Manifest file Activity User Interface User interaction
User interaction
KeyPad ClickListener (onClick(View)) KeyListener (onKeyUp(KeyEvent), onKeyDown(KeyEvent))
TouchScreen TouchListener (onTouchEvent(MotionEvent))
Youssef RIDENE : [email protected]
Mobile and Wireless Systems Programming