android overview
DESCRIPTION
Android Framework and application building blocksTRANSCRIPT
AndroidAndroidFramework and Application Framework and Application
OverviewOverview
By: Ashish AgrawalBy: Ashish Agrawal
12/04/23Android Overview 1
AgendaMobile Application Development (MAD)
Introduction to Android platform
Platform architecture
Application building blocks
Lets Debug
Development tools.
12/04/23Android Overview 2
Introduction to AndroidOpen software platform for mobile development
A complete stack – OS, Middleware, Applications
Powered by Linux operating system
Fast application development in Java
Open source under the Apache 2 license
12/04/23Android Overview 3
12/04/23Android Overview 4
Application Framework
12/04/23Android Overview 5
• API interface
• Activity manager – manages application life cycle.
Applications
12/04/23Android Overview 6
• Built in and user apps
• Can replace built in apps
Application LifecycleApplication run in their own processes (VM, PID)
Processes are started and stopped as needed to run an application's components
Processes may be killed to reclaim resources
12/04/23Android Overview 7
Application Building BlocksActivity
Fragments
Intents
Service (Working in the background)
Content Providers
Broadcast receivers
Action bar
12/04/23Android Overview 8
ActivitiesTypically correspond to one UI screen
Run in the process of the .APK which installed them
But, they can:Be facelessBe in a floating windowReturn a value
12/04/23Android Overview 9
12/04/23Android Overview 10
Fragments
12/04/23Android Overview 11
Fragment represents a behavior or a portion of user interface in an Activity. You can combine multiple fragments in a single activity to build a multi-pane UI and reuse a fragment in multiple activities.
Fragments
12/04/23Android Overview 12
Intents An intent is an abstract description of an operation to be
performed.
Launch an activity
Explicit
Ex: Intent intent = new Intent(MyActivity.this, MyOtherActivity.class)
Implicit : Android selects the best
Ex: Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(“tel:
555-2368”));
startActivity()
Extra parameter Ex: intent.putExtra(name, property);
12/04/23Android Overview 13
Intent FilterRegister Activities, Services, and Broadcast
Receivers as being capable of performing an action on a particular kind of data.
Components that respond to broadcast ‘Intents’
Way to respond to external notification or alarms
Apps can invent and broadcast their own Intent
12/04/23Android Overview 14
ServicesFaceless components that run in the background
No GUI, higher priority than inactive Activities
Usage: responding to events, polling for data, updating Content Providers. However, all in the main thread
E.g. music player, network download etc…
Intent service = new Intent(context, WordService.class);
context.startService(service);12/04/23Android Overview 15
Using the Service
Start the service
Intent serviceIntent = new Intent();
serviceIntent.setAction
("com.wissen.testApp.service.MY_SERVICE");
startService(serviceIntent);
12/04/23Android Overview 16
Bind the serviceServiceConnection conn = new ServiceConnection() {
@Overridepublic void onServiceConnected(ComponentName
name, IBinder service) { }
@Overridepublic void onServiceDisconnected(ComponentName
arg0) {}
}bindService(new Intent("com.testApp.service.MY_SERVICE"), conn, Context.BIND_AUTO_CREATE);}
12/04/23Android Overview 17
Async Task
Asycn task enables easy and proper use of UI thread. This class allows to perform background operations and publish results on the main thread.
12/04/23Android Overview 18
Async Task (Example) private class DownloadFilesTask extends AsyncTask<URL, Integer, Long> { protected Long doInBackground(URL... urls) { int count = urls.length; long totalSize = 0; for (int i = 0; i < count; i++) { totalSize += Downloader.downloadFile(urls[i]); publishProgress((int) ((i / (float) count) * 100)); } return totalSize; }
protected void onProgressUpdate(Integer... progress) { setProgressPercent(progress[0]); }
protected void onPostExecute(Long result) { showDialog("Downloaded " + result + " bytes"); } }
12/04/23Android Overview 19
ContentProvidersEnables sharing of data across applications
E.g. address book, photo gallery
Provides uniform APIs for:queryingdelete, update and insert.
Content is represented by URI and MIME type
12/04/23Android Overview 20
Example private void displayRecords() { String columns[] = new String[] { People.NAME, People.NUMBER }; Uri mContacts = People.CONTENT_URI; Cursor cur = managedQuery(mContacts, columns, null, null, null ); if (cur.moveToFirst()) { String name = null; String phoneNo = null; do { name = cur.getString(cur.getColumnIndex(People.NAME)); phoneNo = cur.getString(cur.getColumnIndex(People.NUMBER));} while (cur.moveToNext()); } }
12/04/23Android Overview 21
Broadcast ReceiversA broadcast receiver is a class which extends
BroadcastReceiver and which is registered as a receiver in an Android Application via the AndroidManifest.xml file(or via code).
<receiver android:name="MyPhoneReceiver"> <intent-filter> <action android:name="android.intent.action.PHONE_STATE"> </action> </intent-filter> </receiver>
12/04/23Android Overview 22
Broadcast Receiverspublic class MyBroadcastReceiver extends BroadcastReceiver
{ @Override public void onReceive(Context context, Intent intent) { Toast.makeText(context,
”BR.”,Toast.LENGTH_LONG).show(); } }
12/04/23Android Overview 23
ActionBar
12/04/23Android Overview 24
ActionBarHome Icon area: The icon on the top left-hand side of the
action bar is sometimes called the “Home” icon. Title area: The Title area displays the title for the action
bar.Tabs area: The Tabs area is where the action bar paints
the list of tabs specified. The content of this area is variable.
Action Icon area: Following the Tabs area, the Action Icon area shows some of the option menu items as icons.
Menu Icon area: The last area is the Menu area. It is a single standard menu icon.
12/04/23Android Overview 25
Debugging
•Reading and Writing Logs
Log.d("MyActivity”, position);
•adb logcat
• Toast :
Toast toast = Toast.makeText(context, text, duration);
toast.show();
Eclipse
developer.android.com
12/04/23Android Overview 26
Debugging Cont.
•Hierarchy Viewer•Connect your device or launch an emulator.•If you have not done so already, install the application you want to work with.•Run the application, and ensure that its UI is visible.•From a terminal, launch hierarchyviewer
12/04/23Android Overview 27
Debugging Cont.
12/04/23Android Overview 28
adb shell dumpsys activity
Debugging Cont.
12/04/23Android Overview 29
Profiling for memory
Development Tools
Eclipse
developer.android.com
12/04/23Android Overview 30
Thank You.
12/04/23Android Overview 31