gtug android iglaset presentation 1 oct
DESCRIPTION
Android iglaset slides from Stockolm GTUG presentation, October 1stTRANSCRIPT
Johan Nilsson [email protected]
@johanni
STHLM Traveling
http://markupartist.com/sthlmtraveling/
"Att surfa till SLs hemsida funkar bättre"
"Helt värdelös."
"Saknar bara realtid. Grym annars"
"Bra app men behövs bokmärken"
"Eftersom programmet inte uppfyller mina basbehov så blir det en etta"
"At last. SL mobile site is crummy on Android and this fills a nice gap. I am hoping for the ability to bookmark locations soon"
Help the developer
http://www.cyrket.com/package/com.xtralogic.android.logcollector
Search in one of Swedens largest liquor databases iglaset.se with comments and ratings.
• Demo • Passing data between activities• Custom list adapters• Handling screen rotation• Some links
Demo
Passing data between activitiesNon-Persistent Objects
• The android.app.Application class• A public static field/method• A HashMap of WeakReferences to Objects• A Singleton class
Persistent Objects • Application Preferences• Files• contentProviders• SQLite DB
http://developer.android.com/intl/zh-CN/guide/appendix/faq/framework.html#3
Using public static can get kinda messy, not that easy to call RouteDetailActivity from another activity
/*** Holds the current selected route, this is referenced by * RouteDetailActivity.*/public static Route route;
Primitive Data Types
intent.putExtra("com.markupartist.iglaset.drinkId", drinkId);
Using Parcelable, we can send more complex objects
http://github.com/johannilsson/iglaset/blob/master/src/com/markupartist/iglaset/provider/Drink.java#L9
intent.putExtra("com.markupartist.iglaset.drink", drink);
List Adapters
SectionedListAdapter
Idea by Jeff Sharkey http://jsharkey.org/blog/2008/08/18/separating-lists-with-headers-in-android-09/
Refactored version at
http://github.com/commonsguy/cw-advandroid/blob/master/ListView/Sections/src/com/commonsware/android/listview/SectionedAdapter.java
SectionedListAdapter
MultipleListAdapter
http://github.com/johannilsson/sthlmtraveling/blob/master/src/com/markupartist/sthlmtraveling/MultipleListAdapter.java
mMultipleAdapter = new MultipleListAdapter();mMultipleAdapter.addAdapter(ADAPTER_FIRST, mFirstAdater);mMultipleAdapter.addAdapter(ADAPTER_SECOND, mSecondAdapter);mMultipleAdapter.addAdapter(ADAPTER_THIRD, mThirdAdapter);
MultipleListAdapter
Paginating Adapter
http://github.com/johannilsson/iglaset/blob/master/src/com/markupartist/iglaset/activity/SearchResultActivity.java#L161
Screen rotation
When switching from portrait to landscape mode or vice-versa, the activity's onDestroy() and onCreate() will be called
Rotate the emulator by pressing Ctrl + F12
onRetainNonConfigurationInstance
@Overridepublic Object onRetainNonConfigurationInstance() { return mDrinks;} @Overridepublic void onCreate(Bundle savedInstanceState) { final ArrayList<Drink> data = (ArrayList<Drink>) getLastNonConfigurationInstance();}
• If it is expensive to serialize• If you can not serialize, network
connections
onSaveInstanceState
@Overrideprotected void onSaveInstanceState(Bundle bundle) { bundle.putParcelableArrayList("drinks", mDrinks);}@Overridepublic void onCreate(Bundle savedInstanceState) { ArrayList<Drink> data = null; if (savedInstanceState != null) { data = savedInstanceState.getParcelableArrayList("drinks"); }}
• If you need to save several objects Might also be called in other cases (when the activity is closed because of low memory)
Some links
• ImageLoaderhttp://wu-media.com/2009/06/android-imageloader-load-images-sequencially-in-the-background/
• Shelveshttp://code.google.com/p/shelves/
• CommonsWarehttp://commonsware.com/AdvAndroid/index.html
• Color debugginghttp://jsharkey.org/blog/2009/04/22/modifying-the-android-logcat-stream-for-full-color-debugging/
• Swedroidhttp://swedroid.se/