Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Intent Receiver
● Application Package
● Android Manifest
Content
Provider ●Defaults to 1 process
per application
Activity Service ●Defaults to 1 thread
Linux Process per application
Application
How do we tell the
system what we
have to offer?
Meet the Manifest
<manifest> <application>
<uses-permission> <activity>
<receiver> <service> <provider>
Meet the Main Thread
Looper
Service
callbacks and UI
updates happen on
the Main Thread
Message
Queue Activity ● Get away from it :)
Main Thread
Linux Process
What does he mean
with GET AWAY FROM
THE MAIN THREAD
??????
Android Security Model
●
Proven security model
●
Process isolation by UID
●
Permission based model
Basic Building Blocks
Activities Services
Content Intent
Providers Receivers
Activities Services
Content Intent
Providers Receivers
Activities
IS
a way to represent a particular
operation
IS NOT
necessarily a screen element
What is a Task ?
If Activities are
managed components
there must be a
life cycle?
How does an Activity look like?
Activity.java + layout.xml
Activity.java
Content Intent
Providers Receivers
Content Providers
Basic Concepts
● Content providers store and retrieve data and make it
accessible to all applications;
● They're the only way to share data across applications;
● There's no common storage area that all Android packages
can access.
● How a content provider actually stores its data under the
covers is up to its designer!
<provider android:name="com.example.autos.AutoInfoProvider"
android:authorities="com.example.autos.autoinfoprovider"
. . . />
</provider>
Activities Services
Content Intent
Providers Receivers
Services
A Service is an application component that
can perform long-running operations in the
background;
http://developer.android.com/guide/topics/manifest/service-element.html
Well well well,
long-running operations
+
background
http://developer.android.com/guide/topics/fundamentals/services.html
“Caution: A service runs in the main thread of its hosting
process the service does not create its own thread and does
not run in a separate process (unless you specify otherwise).”
“If your service is going to do any CPU intensive work or
blocking operations (such as MP3 playback or networking),
you should create a new thread within the service to do that
work.”
http://developer.android.com/guide/topics/fundamentals/services.html
“Caution: A service runs in the main thread of its hosting
process the service does not create its own thread and does
not run in a separate process (unless you specify otherwise).”
“If your service is going to do any CPU intensive work or
blocking operations (such as MP3 playback or networking),
you must create a new thread within the service to do that
work.”
http://developer.android.com/guide/topics/fundamentals/services.html
I__E__ _E__I_E
INTENT SERVICE
______ _______
● Creates a default worker thread;
● Creates a work queue, so you never have
to worry about multi-threading;
● Stops the service for you;
http://developer.android.com/reference/android/app/IntentService.html
Bound
Service
●Allows application
components to bind
to it
●Expose application's
functionality
Hows does it looks like ?
public class ExampleService extends Service {
IBinder mBinder; // interface for clients that bind
http://developer.android.com/guide/topics/fundamentals/bound-services.html
Activities Services
Content Intent
Providers Receivers
Intent Receivers
Its all about Intents!
“Intents is the mechanism by which the applications talk to
each other and with the system”
ACTION_BOOT_COMPLETED - ACTION_BATTERY_CHANGED -
ACTION_POWER_CONNECTED – ACTION_SHUTDOWN –
ACTION_MEDIA_MOUNTED – ACTION_NEW_OUTGOING_CALL
<uses-permission android:name="android.permission.RECEIVE_SMS"></uses-permission>
...
<receiver android:name=".SMSReceiver" android:enabled="true">
<intent-filter>
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
http://developer.android.com/reference/android/content/BroadcastReceiver.html
DOs
● DO run on a background thread if its not UI related;
● DO consider multiple form factors;
● DO respect the user preferences;
● DO consider that you are not running alone on the system;
● DO hire a designer;
● DO collaborate with other applications;
● DO support landscape and portrait;
● DO consider publishing on the Android Market
DON'Ts
● DONT replace the back, home, search and menu features;
● DONT remove the status bar unless you need to;
● DONT allocate objects unless you need to;
● DONT hold Context object references;
● DONT update Widgets toooooooo often;
● DONT wake up the system to do nothing;
● DONT log sensitive user information;
● DONT use non public APIs =X
Development environment
Eclipse + ADT =
http://eclipse.org http://developer.android.com/sdk/eclipse-adt.html
edit+debug+log+compile+package+
navigate file system+analyze memory+
edit user interface+emulate device+
localize+analyze performance+...
Questions ?
Lets Code :)
Android Apps 101
David Marques | March 11th, 2010