Presentation is loading. Please wait.

Presentation is loading. Please wait.

Android Development Tools

Similar presentations


Presentation on theme: "Android Development Tools"— Presentation transcript:

1 Android Development Tools

2 Android App Lifecycle Context Central command center for Android app
The Context class, android.content.Context, fundamental building block of app Provides access to application-wide features, i.e., files, device resources, system-wide services Example: Context context = getApplicationContext( );

3 Android App Lifecycle Activity
Android app is a collection of task, each called an activity Each activity has a unique task or purpose Activity class, android.app.Activity fundamental building block of any app Define & implement an Activity class for each screen in app Extends the Context class, so it has all of the functionality of Context class

4 Android App Lifecycle A simple game app might have following five activities: A startup or splash screen: primary entry point to app. Displays app name & version information. A main menu screen: acts as a switch to drive user to core activities of app. User chooses what they want to do with app A game play screen: where core game play occurs A high scores screen: display game scores or settings A help/about screen: displays information user might need to play the game

5 Android App Lifecycle Lifecycle of an Android Activity
Android app can be multiprocess Multiple apps may run concurrently as long as memory processing power available Apps can have background behavior Apps can be interrupted and paused when phone call occurs Can be only one active app visible to user at a time OS keeps track of all Activity objects by putting them on a stack When a new Activity starts, the Activity on top of stack pauses & new Activity pushed onto top of stack Apps must manage their state & memory, resources, & data Pause & resume seamlessly

6 Android App Lifecycle

7

8 Android App Lifecycle onCreate( ) onResume( )
Single parameter, a Bundle, which is null if new Activity If restarting Activity, Bundle contains previous state information Perform any setup, such as layout & data binding in onCreate( ) onResume( ) When Activity reaches top of stack, onResume() starts Retrieve any instances to resources needed to run Appropriate place to start audio, video, & animations

9 Android App Lifecycle onPause( )
Current Activity is informed that it is being pushed down stack by way of onPause() method Should stop any audio, video, & animations started Deactivate resources such as database Cursor objects Last chance to clean up & release resources not need while in background Need to save uncommitted data System reserves right to kill an activity without further notice after onPause() is called Need to be timely because new foreground Activity is not started until the onPause() method returns

10 Android App Lifecycle Under low-memory conditions, Android OS can kill any Activity that has been paused, stopped, or destroyed. Any Activity not in foreground is subject to shutdown If Activity is killed after onPause(), the onStop() & onDestroy() methods will not be called Release resources in onPause() Killing Activity does not remove it from stack Activity state is saved into a Bundle object When user returns to Activity later, the onCreate() method is called again, this time with a valid Bundle object as the parameter

11 Android App Lifecycle onDestroy( )
Activity is destroyed in normal course of operation Activity has completed its lifecycle Activity is killed by Android OS because it needs resources, but still has time to gracefully destroy your Activity

12

13 Android App Lifecycle Fragment
An activity can be componentized, each is called a fragment Each fragment has a unique task or purpose with parent activity Fragment class, android.app.Fragment Used to organize activity functionality for more flexible user experience across various screen sizes, orientations and aspect ratios Introduced in Android 3.0

14 Android App Lifecycle Consider MP3 music player applications that allows user to view list of artists, drill down to list their albums, drill down to see each track in an album, play a track.

15 Android App Lifecycle On a tablet or a television, you’re wasting a whole lot of space with one Activity per screen On a large enough screen, could implement a standard music library interface. Requires a single screen, single Activity class

16 Android App Lifecycle This could cause you to develop two separate applications: One to work on smaller screens One to work on larger screens Componentize your features and make four fragments, you can mix and match them on the fly Only one codebase to maintain

17 Android App Lifecycle Intent
Android OS uses asynchronous messaging mechanism to match task request with the activity Each request is packaged as an intent Intent class, android.content.Intent Components such as activities & services communicate with one another

18 Android App Lifecycle startActivity (new Intent (getApplicationContext(), MyDrawActivity.class)); This example launches Activity named MyDrawActivity You can use the Intent structure to pass data between activities Intent object is composed of two main parts: The action to be performed The data to be acted upon You can also specify action/data pairs using Intent Action types and Uri objects

19 Android App Lifecycle Uri number = Uri.parse(tel:4445551212);
Intent dial = new Intent(Intent.ACTION_DIAL, number); startActivity(dial); Activities defined with its own package Applications might launch external activities within other applications Ex: CRM application launches Contacts app to browse Contact database, choose contact, & return contact’s unique identifier to CRM

20 Android App Lifecycle There is a close relationship between activities and intents, and application navigation Application navigation: Main menu or list-style screen Drilldown list-style screen Click actions Options menu Action bar-style navigation

21 Android App Lifecycle Service
Tasks that do not require user interaction can be encapsulated in a service A service is most useful when operations are lengthy or need to be done regularly Example: checking a server for new mail Service class, android.app.Service Handles background operations related to Android app Service class extends Context class

22 Android App Lifecycle When you might use a Service:
A weather, , or social network app to routinely check for updates on the network (polling) A game might create a service to download and process the content for the next level in advance of when the user needs it A photo or media app that keeps its data in sync online might implement a service to package and upload new content in the background when the device is idle

23


Download ppt "Android Development Tools"

Similar presentations


Ads by Google