DOC PREVIEW
SDSU CS 696 - Activity States & GUI View Examples

This preview shows page 1-2-3-24-25-26-27-49-50-51 out of 51 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 51 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 51 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 51 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 51 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 51 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 51 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 51 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 51 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 51 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 51 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 51 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

CS 696 Mobile Phone Application DevelopmentFall Semester, 2009Doc 2 Activity States & GUI View ExamplesSept 8, 2009Copyright ©, All rights reserved. 2009 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.2ContentsMercurial & Example RepositoryAndroid PartsActivity Life CycleAndroid Examples3Mercurial & Example RepositoryMercurial4http://mercurial.selenic.com/wiki/Distributed Source Control SystemWritten in PythonMercurial Eclipse5http://www.vectrace.com/mercurialeclipse/Eclipse Plugin for MercurialAdd functionality to Team menu itemCourse Examples Mercurial Repository 6http://bismarck.sdsu.edu/cgi-bin/hg/Web interfaceView onlineDownload zipped fileYou can import the unzipped file using Mercurial Eclipse pluginMercurial clonehg clone http://bismarck.sdsu.edu/cgi-bin/hg/android/HelloWorldYou can import the unzipped file using Mercurial Eclipse pluginLoad directly into EclipseImport...Select "Clone repository using MercialEclipse"Enter URL: http://bismarck.sdsu.edu/cgi-bin/hg/android/HelloWorldYou may have to clean the projectHistory78Android PartsBuilding Blocks Of Android Application9AndroidManifest.xmlActivitiesViewsIntentsServicesNotificationsContent ProvidersAndroidManifest.xml10<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.android.hello2" android:versionCode="1" android:versionName="1.0.0"> <application android:icon="@drawable/icon" android:label="@string/app_name"> <activity android:name=".HelloAndroid" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application></manifest> Contains information about the application needed by the phone to run it@string/app_name indicates that the string is to be found in the string resource file under the label app_name.Activities11Code that does some workHas a life cyclePaused, Killed, etc.Views have an associated activityActivities can be viewlessView12An object that knows how to draw itself to the screenSet of existing views or widgetsCan create your own viewGamesNew widgetsIntent13Used to move from screen to screenContainsDataActionWhat you want doneMAIN, VIEW, PICK, EDIT, etcIntent filterWhat intents an activity can handleTo move to a new screen register an intentstartActivity(anIntent).Service14Code that runs in the backgroundCan be long livedNo UIExample music playerNotifications15Icon that appears in the status barUsed to notify userSMSVoicemailContent Holder16Set of methods to let applications access content provider dataUsed to allow multiple applications access dataAddress book17Activity Life CycleActivity18Single, focused thing that a user can doUsually each screen has its own activityAn application may have multiple screens, hence multiple activitiesAn application runs in its own Linux processActivity States19ActiveRunning activity in foreground of screenPausedLost focus, but still visibleRetains all state informationIn extreme memory situations may be killedStoppedNot visibleRetains all state informationOften will be killedKilled2021Activity Examplepackage edu.sdsu.cs696;import android.app.Activity;import android.os.Bundle;import android.widget.TextView;public class CountStates extends Activity { int paused = 0; int killed = 0; int stopped = 0; TextView text;Activity Example22 public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (savedInstanceState != null) { paused = savedInstanceState.getInt("paused"); killed = savedInstanceState.getInt("killed"); stopped = savedInstanceState.getInt("stopped"); } text = new TextView(this); text.setText("Paused: " + paused + " stopped: " + stopped + " killed " + killed); setContentView(text); }Activity Example23protected void onResume() { super.onResume(); text.setText("Paused: " + paused + " stopped: " + stopped + " killed " + killed); } protected void onStart() { super.onStart(); text.setText("Paused: " + paused + " stopped: " + stopped + " killed " + killed); } protected void onStop() { stopped++; super.onStop(); }Activity Example24 protected void onPause() { paused++; super.onPause(); } protected void onDestroy() { killed++; super.onDestroy(); } protected void onSaveInstanceState(Bundle outState) { outState.putInt("paused", paused); outState.putInt("killed", killed); outState.putInt("stopped", stopped); }}Sample Run2526Android ExamplesString ResourcesLoggingEditTextClick ListenerButtonMenusSome Android Views27AutoCompleteTextViewButtonCheckBoxCheckedTextViewChronometerDatePickerDigitalClockEditTextExpandableListViewGalleryGridViewImageButtonListViewMapView,MultiAutoCompleteTextViewRadioButtonRatingBarScrollViewSeekBarSpinnerTabHostTabWidgetTableRowTimePickerToggleButtonTwoLineListItemVideoViewViewAnimatorWebViewZoomButtonZoomControlsUsing String Resources Example28package sdsu.cs696;import android.app.Activity;import android.os.Bundle;public class HelloAndroid extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); }}src/com.android/hello2/R.java29package sdsu.cs696;public final class R { public static final class attr { } public static final class drawable { public static final int icon=0x7f020000; } public static final class layout { public static final int main=0x7f030000; } public static final class string { public static final int app_name=0x7f040001; public static final int hello=0x7f040000; }}//Autogeneratedres/layout/main.xml30<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" ><TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" /></LinearLayout>res/values/strings.xml31<?xml version="1.0" encoding="utf-8"?><resources> <string name="hello">Hello


View Full Document

SDSU CS 696 - Activity States & GUI View Examples

Download Activity States & GUI View Examples
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 Activity States & GUI View Examples 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 Activity States & GUI View Examples 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?