1 / 42

Android Jump Start: Application Development

Learn the basics of Android application development, including Java programming, activity lifecycle, user interface design, and using intents, broadcasts, and notifications.

brubio
Download Presentation

Android Jump Start: Application Development

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Android Jump Start: Application Development Marcus Chou

  2. Smartphone?

  3. Smartphone?

  4. Smartphone?

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

  6. Market trend (cont.)

  7. App Store

  8. Smart phone of nowadays Blonde??

  9. Wallpaper of Android

  10. Installed applications

  11. Applications menu

  12. Notification

  13. Preference

  14. Android Market

  15. Android Market (cont.)

  16. Prerequisites • Java programming skills • Android SDK

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

  18. Android SDK • Emulator • Tools • Document • Library • Sample code    Reference:http://code.google.com/android/documentation.html

  19. Four building block... • Activity • Broadcast Intent Receiver • Service • Content Provider

  20. 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

  21. Activity (cont.) Resource • Drawable • Layout • Values

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

  23. 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); }}

  24. 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.

  25. Explicit Intents

  26. Explicit Intents (cont.) Intent intent = new Intent(ItemList.this,VideoPlayer.class);  intent.putExtra("file_path", selectedItem.getFilePath()); startActivity(intent);

  27. 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        }

  28. Broadcast Intent Receiver • Broadcast Receiver • Notification

  29. 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"));            }}

  30. Broadcast Receiver (cont.)

  31. 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>

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

  33. 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); } 

  34. Notification (cont.)

  35. Service • A Service is code that is long-lived and runs without a UI • Use Context.bindService() to connect to the service

  36. 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" /> ....

  37. 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

  38. 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);    }}

  39. Content Provider (cont.)

  40. 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>

  41. Security (cont.)

  42. 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 Group http://groups.google.com/group/android-platform

More Related