1

I am currently working on an Android App which has different service dimensions, such as " service order", "route planning", "photo gallery" and a central login. so far i implemented each "screen" (and by screen i mean actually the layout of a screen) as a seperate class, which loads a specific layout and handles all listeners and core functionalities such as calling webservices in a thread, receiving answers etc. I am not quite sure if this is the best way to implemnt mulitiple layout-screens.

The Android dev guideline proposes to use single activities for each "screen layout". However I doubt that this is the most effective way of doing things. Since i need information for each "layout" which are retrieved by the central login (here: a user object). Since an activity (as far as i understand) is a seperate thread, the passing and retrieving of information seems not very practical.

I would like to get your oppinions/feedback on that and thanks for any hint or tip.

So far my structure looks like :

  • Activity
    • loads login layout (res/layout/login.xml with setlContentView)
    • depending on buttonclick other resources are loaded and initialized (means listeners are added etc.)

Greets Peter

EboMike
  • 76,846
  • 14
  • 164
  • 167
Peter
  • 11
  • 2

2 Answers2

3

The dev guidelines recommend that for a reason. It IS the most effective way of doing things. You may complain about having to store your data so it can be passed along from activity to activity, but guess what? You're developing an app for a phone! At any point in time, the phone could ring, forcing the user to switch away from your app. Or the user could just choose to temporarily look at a different app. If your app goes back to square one after switching back and lost all data, the user will be understandably angry.

EboMike
  • 76,846
  • 14
  • 164
  • 167
  • Thanks for the feedback, so you would recommend to rather store this data persistently on the phone, than to pass it from activity to activity ? You got a valid point here, so even if i pass the data from activity to activty, it will be lost if the app is interrupted...so i do need to store it on the phone (since i do not want the user to login each time the app is interrupted) – Peter Dec 21 '10 at 09:31
  • Depends on how long you want it to be around for. If you store it in the SharedPreferences, it will be around even after the user resets the phone. Kinda nice. But there's no harm in just passing it along in the intent - that's good enough to handle the normal cases (including changing orientation of the phone). – EboMike Dec 21 '10 at 09:33
0

Don't know if this would be suitable for your app, but another option could be to split off the core data handling into a Service, and have your app be just a UI frontend which communicates with that service.

svdree
  • 13,298
  • 4
  • 28
  • 21