DOC PREVIEW
SDSU CS 696 - Android Activity Life Cycle

This preview shows page 1-2-16-17-18-33-34 out of 34 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 34 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 34 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 34 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 34 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 34 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 34 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 34 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 34 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

CS 696 Emerging Web and Mobile TechnologiesSpring Semester, 2011Doc 19 Android Activity Life CycleMar 24, 2011Copyright ©, All rights reserved. 2011 SDSU & Roger Whitney, 5500 Campanile Drive, San Diego, CA 92182-7700 USA. OpenContent (http://www.opencontent.org/opl.shtml) license defines the copyright on this document.Thursday, March 24, 2011References2Android Developer's Guide, http://developer.android.com/guide/index.htmlCS 696 Mobile Phone Application Development, Fall 2009, http://www.eli.sdsu.edu/courses/fall09/cs696/notes/index.htmlThursday, March 24, 2011Examples3http://developer.android.com/resources/browser.htmlandroidInstallation/platforms/android-10/samples/ApiDemosSourceThursday, March 24, 20114Activities & TasksThursday, March 24, 2011Android Application5Set of related activitiesCombined into one application file (.apk) Launch-able from the home screenThursday, March 24, 2011Tasks6Sequence of activities the user follows to accomplish an objectiveA user canInterrupt a task to start a new taskResume the first task where they left offThursday, March 24, 2011Tasks & Applications7Many applications are self containedSo task is sequence of activities from the applicationSome applications use activities from other applicationsUse phoneShow contactsUse Web browserPlay musicSo task is sequence of activities from multiple applicationsThursday, March 24, 2011Interrupting a Task8User presses Home and starts an applicationNotificationsThursday, March 24, 2011Activity Stack9Back StackHistory of activities used by userMay include activities of different applicationsBack button Removes top of activity stackMakes next activity activeHome buttonActivity stack remainsStarting another application starts new activity stackStack only goes back to the start of the application at HomeThursday, March 24, 2011Sample User Flow10RestaurantsAllBy LocationBy TypeChipolteStar of IndiaTaste of ThaiAllBackChipolteBack5842 Hardy AveSan Diego, CA 92115619.265.2778Open 11:00 AM to 10:00 PMMap Send a TextTo Map ActivityThursday, March 24, 2011Activity Stack11HomeRestaurantsAllChipotleGoogle MapsActivity StackRestaurant ActivitiesMaps ActivitiesThursday, March 24, 2011Multiple Activity Stacks12HomeRestaurantsAllChipotleGoogle MapsActivity StackMonth ViewDay ViewLaunch CalendarActivity StackThursday, March 24, 2011Applications & Activity Stacks13Launching a non-running applicationCreate new activity stackPut application's beginning activity on stackLaunching a running applicationShow activity on top of applications activity stackThat activity may be from another applicationExceptionsSome background activities return to their initial screenContacts & GallerySome activities continue to run while in the backgroundMusic playerThursday, March 24, 2011See http://developer.android.com/guide/practices/ui_guidelines/activity_task_design.html for a complete descriptionActivity Lifecycle States14Active (Resumed)Running activity in foreground of screenPausedLost focus, but still visibleRetains all state informationIn extreme memory situations may be killedStoppedNot visibleRetains all state informationOften will be killedThursday, March 24, 201115Thursday, March 24, 2011Spend time on this slide16Saving StateWhen low on memory system will kill activities In activity stackNot visibleWhen user goes back to killed activity Activity must appear as it did before it was killedMust save state of activitySystem will save state of viewsThursday, March 24, 2011Types of State to Save17Dynamic instance stateState of instance variables of activityNeeded so activity object can operatePersistent stateInformation that should be available next time application is runContact information in Address bookOverlapPersistent state is usually subset of dynamic stateThursday, March 24, 2011Saving Persistent State18Do it in the onPause() methodIt will always be calledOne method that will always be called before activity is killedonStop)() and onDestroy() are not always calledThursday, March 24, 2011onStop()19Called when activity is no longer visibleNot always calledThursday, March 24, 2011onDestroy()20Used to free resources like threadsThere are situations when "system will simply kill the activity's hosting process without calling this method"Thursday, March 24, 2011finnish()21Sending "finnish()" to an activity will kill the activityNormally don't call this methodThursday, March 24, 2011Saving/Restoring Dynamic Instance State22protected void onSaveInstanceState(Bundle outState) Called after onPauseSave data in bundleRestore state in onCreate oronRestoreInstanceStateThursday, March 24, 201123Activity State Change ExampleThursday, March 24, 201124Showing State ChangesCount number of times calledonPaused(), onStopped(), onDestroy()Send to screen message from each onXXX()Send to log a message from each onXXX()Touch lower textfield - start web browserTouch upper textfield - open dialogStart upThursday, March 24, 2011Web Browser for second activity25touchbackbuttonThursday, March 24, 2011Web Browser for second activity26backbuttonbackbuttonThursday, March 24, 2011Dialog27touchbackThursday, March 24, 2011Rotation28Thursday, March 24, 201129Source CodeThursday, March 24, 2011onCreate30public class CountStates extends Activity implements View.OnTouchListener { int paused = 0; int killed = 0; int stopped = 0; TextView text; TextView logger; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (savedInstanceState != null) { paused = savedInstanceState.getInt("paused"); killed = savedInstanceState.getInt("killed"); stopped = savedInstanceState.getInt("stopped"); } setContentView(R.layout.main); text = (EditText) this.findViewById(R.id.text); text.setOnTouchListener(this); logger = (EditText) this.findViewById(R.id.log); logger.setText(""); logger.setOnTouchListener(this); updateText("onCreate"); }Thursday, March 24, 2011Touch and upDateText31 public boolean onTouch(View v, MotionEvent event) { if (v == logger) { Intent web = new Intent(Intent.ACTION_WEB_SEARCH); web.putExtra(SearchManager.QUERY, "Roger Whitney"); startActivity(web); } if (v == text) { showDialog(0); } return true; } private void updateText(String eventType) { Log.i("rew", eventType); text.setText("Paused: " + paused + " stopped: " + stopped + " killed " + killed); logger.append(eventType + "\n"); }Thursday, March 24, 2011Dialog32protected Dialog


View Full Document

SDSU CS 696 - Android Activity Life Cycle

Download Android Activity Life Cycle
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Android Activity Life Cycle and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Android Activity Life Cycle 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?