android jump start: application development

42
Android Jump Start: Application Development Marcus Chou

Upload: tameka

Post on 05-Jan-2016

46 views

Category:

Documents


0 download

DESCRIPTION

Android Jump Start: Application Development. Marcus Chou. Smartphone?. Smartphone?. Smartphone?. Market trend. Close to 20% of U.S. smartphone owners spent $100 on apps in 2008           -- ABI Research Survey. Market trend (cont.). App Store. Smart phone of nowadays. Blonde??. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Android Jump Start: Application Development

Android Jump Start: Application Development

Marcus Chou

Page 2: Android Jump Start: Application Development

Smartphone?

Page 3: Android Jump Start: Application Development

Smartphone?

Page 4: Android Jump Start: Application Development

Smartphone?

Page 5: Android Jump Start: Application Development

Market trend

 Close to 20% of U.S. smartphone owners spent $100 on apps in 2008          -- ABI Research Survey 

  

Page 6: Android Jump Start: Application Development

Market trend (cont.)

Page 7: Android Jump Start: Application Development

App Store

Page 8: Android Jump Start: Application Development

Smart phone of nowadays

Blonde??

Page 9: Android Jump Start: Application Development

Wallpaper of Android

Page 10: Android Jump Start: Application Development

Installed applications

Page 11: Android Jump Start: Application Development

Applications menu

Page 12: Android Jump Start: Application Development

Notification

Page 13: Android Jump Start: Application Development

Preference

Page 14: Android Jump Start: Application Development

Android Market

Page 15: Android Jump Start: Application Development

Android Market (cont.)

Page 16: Android Jump Start: Application Development

Prerequisites

 • Java programming skills • Android SDK

Page 17: Android Jump Start: Application Development

Java

 • Simple, Object Oriented, and familiar• Interface, Abstract, extends, implement    Reference:http://java.sun.com/docs/books/tutorial/

Page 18: Android Jump Start: Application Development

Android SDK

• Emulator• Tools• Document• Library• Sample code 

  Reference:http://code.google.com/android/documentation.html

Page 19: Android Jump Start: Application Development

Four building block...

• Activity• Broadcast Intent Receiver• Service• Content Provider

Page 20: Android Jump Start: Application Development

Activity

• A activity is usually a single screen in an application

• A user interface compsed of Views and respond to events

• A application may consist of many  activities

Page 21: Android Jump Start: Application Development

Activity (cont.) Resource

• Drawable• Layout• Values

Page 22: Android Jump Start: Application Development

Activity (cont.) UI Layout Design<TabHost>    <LinearLayout>        <LinearLayout>            <ImageView/>            <ScrollView>                <TextView/>            </ScrollView>        </LinearLayout>        <LinearLayout>            <TabWidget/>            <FrameLayout/>        </LinearLayout>    </LinearLayout></TabHost>

Page 23: Android Jump Start: Application Development

Activity (cont.)

public class About extends Activity{    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.about);                String about = this.getIntent().getExtras().getString("about");        TextView tv=(TextView)this.findViewById(R.id.about);        tv.setText(about);}}

Page 24: Android Jump Start: Application Development

Activity (cont.)

• Use "Intent" to activate the screen (Activity)  • The two most important parts of the intent

data structure are the action and the data to act upon.

Page 25: Android Jump Start: Application Development

Explicit Intents

Page 26: Android Jump Start: Application Development

Explicit Intents (cont.)

  

Intent intent = new Intent(ItemList.this,VideoPlayer.class);  intent.putExtra("file_path", selectedItem.getFilePath());

startActivity(intent);

Page 27: Android Jump Start: Application Development

Implicit Intents

        Uri uri = Uri.parse("http://tw.youtube.com/watch?v=S6o7rwrxt4g");                Intent intent = new Intent(Intent.ACTION_VIEW, uri);        try {          if (startActivity(intent)) {                      // success          }        } catch (ActivityNotFoundException ex) {          // fail        }

Page 28: Android Jump Start: Application Development

Broadcast Intent Receiver

 • Broadcast Receiver • Notification

Page 29: Android Jump Start: Application Development

Broadcast Receiver (cont.)

private void registerBroadcastListener(){        IntentFilter filter = new IntentFilter(Intent.ACTION_TIME_TICK );        this.registerReceiver(this.mBlackdidiListener, filter);} private  class BlackdidiBroadcastListener extends  BroadcastReceiver {            public void onReceive(Context context, Intent intent) {                startActivity((new Intent(BlackdidiSample.this, About.class)).putExtra("about", "time tick"));            }} 

Page 30: Android Jump Start: Application Development

Broadcast Receiver (cont.)

Page 31: Android Jump Start: Application Development

Broadcast Receiver (cont.)<receiver android:name="com.blackdidi.comp.BootReceiver">   <intent-filter>       <action android:name="android.intent.action.BOOT_COMPLETED" />    </intent-filter> </receiver>        <receiver android:name="com.blackdidi.comp.ConnectivityReceiver">    <intent-filter>         <action android:name="android.net.conn.CONNECTIVITY_CHANGE" />    </intent-filter> </receiver>

Page 32: Android Jump Start: Application Development

Notification (cont.)

public class BlackdidiSample extends Activity {    private NotificationManager mNM;    ...    public void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        mNM = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);        ...     }    ...}   

Page 33: Android Jump Start: Application Development

Notification (cont.)

private void showNotification() {    CharSequence text = getText(R.string.hello_notification);

    Notification notification = new      Notification(R.drawable.star_big_on, text,                System.currentTimeMillis());

    PendingIntent contentIntent = PendingIntent.getActivity(this, 0,( new Intent(this, About.class)).putExtra("about", "yoho, blackdidi"), 0);

        notification.setLatestEventInfo(this, getText(R.string.hello_notification),text, contentIntent);

        mNM.notify(R.string.app_name, notification);} 

Page 34: Android Jump Start: Application Development

Notification (cont.)

Page 35: Android Jump Start: Application Development

Service

  • A Service is code that is long-lived and runs

without a UI• Use Context.bindService() to connect to the

service

Page 36: Android Jump Start: Application Development

Service (cont.)

<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android"      android:versionCode="1"      android:versionName="1.0.0" package="com.blackdidi.podcast">    <application android:icon="@drawable/icon" android:label="@string/app_name">        <service android:name=".xml.ChannelService" />        <service android:name=".download.DownloadService" />....

Page 37: Android Jump Start: Application Development

Content Provider

A content provider is only required if you need to share data between multiple applications. 

 • Querying for Data• Modifying Data• Adding a Record• Deleting a Record

Page 38: Android Jump Start: Application Development

Content Provider (cont.)public class BlackdidiList extends ListActivity{   protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);             Cursor c = getContentResolver().query(CallLog.Calls.CONTENT_URI, null, null, null, null);        startManagingCursor(c);        ListAdapter adapter = new SimpleCursorAdapter(this,                android.R.layout.simple_list_item_2, c,                         new String[] {CallLog.Calls.NUMBER , CallLog.Calls.CACHED_NAME },                         new int[] { android.R.id.text1, android.R.id.text2 });        setListAdapter(adapter);    }}

Page 39: Android Jump Start: Application Development

Content Provider (cont.)

Page 40: Android Jump Start: Application Development

Security<uses-permission android:name="android.permission.INTERNET"></uses-permission> <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/><uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission><uses-permission android:name="android.permission.ACCESS_WIFI_STATE"></uses-permission><uses-permission android:name="android.permission.WAKE_LOCK"></uses-permission><uses-permission android:name="android.permission.BATTERY_STATS"></uses-permission>

Page 41: Android Jump Start: Application Development

Security (cont.)

Page 42: Android Jump Start: Application Development

Reference

Android Developers Site    http://developer.android.com/

Android Developers Blog    http://developer.android.com/

Android Developers Group    http://groups.google.com/group/android-developers

Android Platform Discussion Grouphttp://groups.google.com/group/android-platform