Mobile and Wireless Systems Programming

flosssnailsMobile - Wireless

Dec 10, 2013 (3 years and 7 months ago)

91 views

Introduction
Application Components
Activating components
Developping apps
Mobile and Wireless Systems Programming
Application Fundamentals
Youssef RIDENE:youssef.ridene@univ-pau.fr
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:youssef.ridene@univ-pau.fr
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:youssef.ridene@univ-pau.fr
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:youssef.ridene@univ-pau.fr
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:youssef.ridene@univ-pau.fr
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:youssef.ridene@univ-pau.fr
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:youssef.ridene@univ-pau.fr
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:youssef.ridene@univ-pau.fr
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:youssef.ridene@univ-pau.fr
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:youssef.ridene@univ-pau.fr
Mobile and Wireless Systems Programming
Introduction
Application Components
Activating components
Developping apps
ADT
App structure
Resources
The Manifest file
Activity
User Interface
User interaction
Youssef RIDENE:youssef.ridene@univ-pau.fr
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:youssef.ridene@univ-pau.fr
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:youssef.ridene@univ-pau.fr
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>...</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>
<pr ov i de r>...</pr ov i de r>
Youssef RIDENE:youssef.ridene@univ-pau.fr
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
<?xml v e r s i o n="1.0"encodi ng="ut f 8"?>
<mani f es t...>
<a p p l i c a t i o n...>
<a c t i v i t y andr oi d:name="com.uppa.m2.Fi r s t Ac t i v i t y"
a ndr oi d:i c on="@drawabl e/i con.png"
a n d r o i d:l a b e l ="@s t r i ng/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>
</mani f es t>
Youssef RIDENE:youssef.ridene@univ-pau.fr
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 onCreate(Bundle savedInstanceState)
void onStart()
void onRestart()
void onResume()
void onPause()
void onStop()
void onDestroy()
Youssef RIDENE:youssef.ridene@univ-pau.fr
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.he l l o a ndr o i d;
import andr oi d.app.Ac t i v i t y;
import andr oi d.os.Bundl e;
publ i c cl as s Hel l oAndr oi d extends Ac t i v i t y {
/ Cal l e d when t he a c t i v i t y i s f i r s t c r e at e d./
@Over r i de
publ i c voi d onCr eat e ( Bundl e s av e dI ns t anc e St at e ) {
super.onCr eat e ( s av e dI ns t anc e St at e );
set Cont ent Vi ew (R.l ayout.main );
}
}
Youssef RIDENE:youssef.ridene@univ-pau.fr
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)
<?xml v e r s i o n="1.0"encodi ng="ut f 8"?>
<Li near Layout xml ns:andr oi d="ht t p://schemas.andr oi d.com/apk/r e s/andr oi d"
andr oi d:l ayout _wi dt h="f i l l _p a r e n t"
andr oi d:l ayout _he i ght="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">
<TextVi ew a ndr o i d:i d="@+i d/my_textView"
andr oi d:l ayout _wi dt h="wrap_content"
andr oi d:l ayout _he i ght="wrap_content"
a ndr o i d:t e x t="Hel l o,￿ I ￿am￿a￿TextVi ew"/>
<Button a ndr o i d:i d="@+i d/my_button"
andr oi d:l ayout _wi dt h="wrap_content"
andr oi d:l ayout _he i ght="wrap_content"
a ndr o i d:t e x t="Hel l o,￿ I ￿am￿a￿Button"/>
</Li near Layout>
Youssef RIDENE:youssef.ridene@univ-pau.fr
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:youssef.ridene@univ-pau.fr
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:youssef.ridene@univ-pau.fr
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:youssef.ridene@univ-pau.fr
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:youssef.ridene@univ-pau.fr
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:youssef.ridene@univ-pau.fr
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:youssef.ridene@univ-pau.fr
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:youssef.ridene@univ-pau.fr
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:youssef.ridene@univ-pau.fr
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:youssef.ridene@univ-pau.fr
Mobile and Wireless Systems Programming