1 / 18

Android Tutorial

Android Tutorial. naderjawad@gmail.com. Android. Written in Java Utilizes Dalvik VM Just in time (JIT) compilation since Android 2.2. Java Tips. Similar syntax to C/C++ All function/procedure arguments passed in by value Class objects are references that are passed by value

hedy
Download Presentation

Android Tutorial

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 Tutorial naderjawad@gmail.com

  2. Android • Written in Java • Utilizes Dalvik VM • Just in time (JIT) compilation since Android 2.2

  3. Java Tips • Similar syntax to C/C++ • All function/procedure arguments passed in by value • Class objects are references that are passed by value • No support for multiple inheritance • Does support multiple interfaces • Garbage collected (Hooray!) • Beware! Can still create memory leaks!

  4. Java Tips • All methods are virtual by default • Java naming convention

  5. Java Memory Leaks • Every class object is a reference to the object • Java VM keeps track of reference counts to every object • Once nothing refers to an object anymore it gets garbage collected • Once finished with an object, set it to null to release the memory

  6. Android Components • Activity • Code that has a user interface associated with it • Implemented as a stack • Service • Code that runs in the background without a user interface • Broadcast Receiver • Code that runs in response to Android OS or Application intents(messages)

  7. Android Components (cont.) • Content Providers • Database that is exposed to all applications to consume • Intents • Messages that are passed throughout the Android OS/ other applications

  8. Building Android Applications • Create UI using XML • New UI dev tools make building UIs awesome • Once an xml file is saved, the Eclipse ADT tools create an R.java • DO NOT MODIFY R.java!! • Never a good idea, ever like forealz

  9. Building Android Applications • Reference UI elements by utilizing findViewById(int) member method on View object • Ex. • Button b = (Button)findViewById(R.id.myButton); • findViewById is expensive!

  10. Starting New Activities • Intent i = new Intent(); • i.setClass(callingActivity.this, calleeActivity.this); • startActivity(i);

  11. Passing objects to Activities • Easiest way, just create a static data structure • Accessible to all activities within an application • Pass objects through bundles in an intent • Intent i = new Intent(); • i.putExtra(key, stringValue); • Retreive object • Bundle b = getIntent().getExtras(); • String o = b.getString(key);

  12. Passing values to Activities • Can pass primitive types through bundles • char, int, float, double, String • Can pass custom objects by implementing Parcelable interface • http://developer.android.com/reference/android/os/Parcelable.html

  13. Be careful of ANRs! • ANR = Application Not Responding • Occurs when application is not responsive to touch events for ~5 seconds • All major computation should be done on a separate thread • Use threads • Need a runnable object to update the UI thread • AsyncTask • http://developer.android.com/reference/android/os/AsyncTask.html

  14. Running Android Apps • Can use Android emulator • Obnoxiously slow • Better emulator coming soon, not quite sure when • Debugging on device is king!

  15. Building Apps for Varying Devices • Java code same (mostly) • Add additional xml layout files for each device • Save in corresponding directories • layout-land • Folder for landscape view • layout-mdpi • Folder for layouts for devices with medium density displays

  16. Building Apps for Varying Devices • Save copies of same image in different resolutions in drawable folders • drawable-hdpi • drawable-mdpi • drawable-ldpi

  17. Android Extra Fun Stuff • Renderscript • New library of APIs that allows for easy animation creation • Also useful for complex computation • ADK • Accessory Development Kit • Allows for development of accessories that interface with devices through USB • Based off of Arduino • NDK (native development kit) • JNI (Java Native Interface) • Allows for glue between Java and C code for extra performance • Note just writing your application in C++ using the NDK doesn’t make it faster than normal Java implementation

  18. Hints Tips Tricks • Android.com • Google IO Sessions • http://www.google.com/events/io/2011/sessions.html • Android developer blog • http://android-developers.blogspot.com • Stackoverflow • google

More Related