gtug android iglaset presentation 1 oct

23
Johan Nilsson [email protected] @johanni

Upload: johan-nilsson

Post on 14-May-2015

1.015 views

Category:

Technology


2 download

DESCRIPTION

Android iglaset slides from Stockolm GTUG presentation, October 1st

TRANSCRIPT

Page 1: GTUG Android iglaset Presentation 1 Oct

Johan Nilsson [email protected]

@johanni

Page 2: GTUG Android iglaset Presentation 1 Oct
Page 3: GTUG Android iglaset Presentation 1 Oct

STHLM Traveling

http://markupartist.com/sthlmtraveling/

Page 4: GTUG Android iglaset Presentation 1 Oct

"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"

Page 5: GTUG Android iglaset Presentation 1 Oct

Help the developer

http://www.cyrket.com/package/com.xtralogic.android.logcollector

Page 6: GTUG Android iglaset Presentation 1 Oct

Search in one of Swedens largest liquor databases iglaset.se with comments and ratings.

Page 7: GTUG Android iglaset Presentation 1 Oct

• Demo • Passing data between activities• Custom list adapters• Handling screen rotation• Some links

Page 8: GTUG Android iglaset Presentation 1 Oct

Demo

 

Page 9: GTUG Android iglaset Presentation 1 Oct

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

Page 10: GTUG Android iglaset Presentation 1 Oct

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;

Page 11: GTUG Android iglaset Presentation 1 Oct

Primitive Data Types

intent.putExtra("com.markupartist.iglaset.drinkId", drinkId);

Page 12: GTUG Android iglaset Presentation 1 Oct

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); 

Page 13: GTUG Android iglaset Presentation 1 Oct

List Adapters

 

Page 14: GTUG Android iglaset Presentation 1 Oct

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

Page 15: GTUG Android iglaset Presentation 1 Oct

SectionedListAdapter

Page 16: GTUG Android iglaset Presentation 1 Oct

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);

Page 17: GTUG Android iglaset Presentation 1 Oct

MultipleListAdapter

Page 18: GTUG Android iglaset Presentation 1 Oct

Paginating Adapter

http://github.com/johannilsson/iglaset/blob/master/src/com/markupartist/iglaset/activity/SearchResultActivity.java#L161

Page 19: GTUG Android iglaset Presentation 1 Oct

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

Page 20: GTUG Android iglaset Presentation 1 Oct

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

Page 21: GTUG Android iglaset Presentation 1 Oct

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)

Page 22: GTUG Android iglaset Presentation 1 Oct

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/ 

Page 23: GTUG Android iglaset Presentation 1 Oct

Thank you

[email protected]@johanni

See you at the Android Hackathon at bwin 28/11