Download - Android overview
![Page 1: Android overview](https://reader033.vdocuments.mx/reader033/viewer/2022060109/55580118d8b42ae31c8b4e8d/html5/thumbnails/1.jpg)
AndroidAndroidFramework and Application Framework and Application
OverviewOverview
By: Ashish AgrawalBy: Ashish Agrawal
12/04/23Android Overview 1
![Page 2: Android overview](https://reader033.vdocuments.mx/reader033/viewer/2022060109/55580118d8b42ae31c8b4e8d/html5/thumbnails/2.jpg)
AgendaMobile Application Development (MAD)
Introduction to Android platform
Platform architecture
Application building blocks
Lets Debug
Development tools.
12/04/23Android Overview 2
![Page 3: Android overview](https://reader033.vdocuments.mx/reader033/viewer/2022060109/55580118d8b42ae31c8b4e8d/html5/thumbnails/3.jpg)
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
![Page 4: Android overview](https://reader033.vdocuments.mx/reader033/viewer/2022060109/55580118d8b42ae31c8b4e8d/html5/thumbnails/4.jpg)
12/04/23Android Overview 4
![Page 5: Android overview](https://reader033.vdocuments.mx/reader033/viewer/2022060109/55580118d8b42ae31c8b4e8d/html5/thumbnails/5.jpg)
Application Framework
12/04/23Android Overview 5
• API interface
• Activity manager – manages application life cycle.
![Page 6: Android overview](https://reader033.vdocuments.mx/reader033/viewer/2022060109/55580118d8b42ae31c8b4e8d/html5/thumbnails/6.jpg)
Applications
12/04/23Android Overview 6
• Built in and user apps
• Can replace built in apps
![Page 7: Android overview](https://reader033.vdocuments.mx/reader033/viewer/2022060109/55580118d8b42ae31c8b4e8d/html5/thumbnails/7.jpg)
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
![Page 8: Android overview](https://reader033.vdocuments.mx/reader033/viewer/2022060109/55580118d8b42ae31c8b4e8d/html5/thumbnails/8.jpg)
Application Building BlocksActivity
Fragments
Intents
Service (Working in the background)
Content Providers
Broadcast receivers
Action bar
12/04/23Android Overview 8
![Page 9: Android overview](https://reader033.vdocuments.mx/reader033/viewer/2022060109/55580118d8b42ae31c8b4e8d/html5/thumbnails/9.jpg)
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
![Page 10: Android overview](https://reader033.vdocuments.mx/reader033/viewer/2022060109/55580118d8b42ae31c8b4e8d/html5/thumbnails/10.jpg)
12/04/23Android Overview 10
![Page 11: Android overview](https://reader033.vdocuments.mx/reader033/viewer/2022060109/55580118d8b42ae31c8b4e8d/html5/thumbnails/11.jpg)
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.
![Page 12: Android overview](https://reader033.vdocuments.mx/reader033/viewer/2022060109/55580118d8b42ae31c8b4e8d/html5/thumbnails/12.jpg)
Fragments
12/04/23Android Overview 12
![Page 13: Android overview](https://reader033.vdocuments.mx/reader033/viewer/2022060109/55580118d8b42ae31c8b4e8d/html5/thumbnails/13.jpg)
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
![Page 14: Android overview](https://reader033.vdocuments.mx/reader033/viewer/2022060109/55580118d8b42ae31c8b4e8d/html5/thumbnails/14.jpg)
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
![Page 15: Android overview](https://reader033.vdocuments.mx/reader033/viewer/2022060109/55580118d8b42ae31c8b4e8d/html5/thumbnails/15.jpg)
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
![Page 16: Android overview](https://reader033.vdocuments.mx/reader033/viewer/2022060109/55580118d8b42ae31c8b4e8d/html5/thumbnails/16.jpg)
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
![Page 17: Android overview](https://reader033.vdocuments.mx/reader033/viewer/2022060109/55580118d8b42ae31c8b4e8d/html5/thumbnails/17.jpg)
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
![Page 18: Android overview](https://reader033.vdocuments.mx/reader033/viewer/2022060109/55580118d8b42ae31c8b4e8d/html5/thumbnails/18.jpg)
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
![Page 19: Android overview](https://reader033.vdocuments.mx/reader033/viewer/2022060109/55580118d8b42ae31c8b4e8d/html5/thumbnails/19.jpg)
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
![Page 20: Android overview](https://reader033.vdocuments.mx/reader033/viewer/2022060109/55580118d8b42ae31c8b4e8d/html5/thumbnails/20.jpg)
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
![Page 21: Android overview](https://reader033.vdocuments.mx/reader033/viewer/2022060109/55580118d8b42ae31c8b4e8d/html5/thumbnails/21.jpg)
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
![Page 22: Android overview](https://reader033.vdocuments.mx/reader033/viewer/2022060109/55580118d8b42ae31c8b4e8d/html5/thumbnails/22.jpg)
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
![Page 23: Android overview](https://reader033.vdocuments.mx/reader033/viewer/2022060109/55580118d8b42ae31c8b4e8d/html5/thumbnails/23.jpg)
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
![Page 24: Android overview](https://reader033.vdocuments.mx/reader033/viewer/2022060109/55580118d8b42ae31c8b4e8d/html5/thumbnails/24.jpg)
ActionBar
12/04/23Android Overview 24
![Page 25: Android overview](https://reader033.vdocuments.mx/reader033/viewer/2022060109/55580118d8b42ae31c8b4e8d/html5/thumbnails/25.jpg)
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
![Page 26: Android overview](https://reader033.vdocuments.mx/reader033/viewer/2022060109/55580118d8b42ae31c8b4e8d/html5/thumbnails/26.jpg)
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
![Page 27: Android overview](https://reader033.vdocuments.mx/reader033/viewer/2022060109/55580118d8b42ae31c8b4e8d/html5/thumbnails/27.jpg)
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
![Page 28: Android overview](https://reader033.vdocuments.mx/reader033/viewer/2022060109/55580118d8b42ae31c8b4e8d/html5/thumbnails/28.jpg)
Debugging Cont.
12/04/23Android Overview 28
adb shell dumpsys activity
![Page 29: Android overview](https://reader033.vdocuments.mx/reader033/viewer/2022060109/55580118d8b42ae31c8b4e8d/html5/thumbnails/29.jpg)
Debugging Cont.
12/04/23Android Overview 29
Profiling for memory
![Page 30: Android overview](https://reader033.vdocuments.mx/reader033/viewer/2022060109/55580118d8b42ae31c8b4e8d/html5/thumbnails/30.jpg)
Development Tools
Eclipse
developer.android.com
12/04/23Android Overview 30
![Page 31: Android overview](https://reader033.vdocuments.mx/reader033/viewer/2022060109/55580118d8b42ae31c8b4e8d/html5/thumbnails/31.jpg)
Thank You.
12/04/23Android Overview 31