I'm quite new to Android development and face UI implementation issues. Namely I'm trying to find a good way (design pattern?) that addresses view hierarchy and navigation between views (with history). Does is always has to be about launching new Activity
? I don't want to learn bad habits during my first steps with Android SDK, hence my question. Your personal approaches you find good to follow or any links to resources/tutorials elaborating on the subject would be appreciated.
views:
63answers:
3It is recomended you launch new Activities because it is the best way which Android is able to manage the cycle of live of tasks in your application.
You could make views on the fly and you could handle with setContentView() and a good controlling code for the events, but you will get a monolitic interface in a tangled mess.
Try to make a little analysis for the interface of your application with the user and it will show you the main screens and activities. It is easy, it is efficient... :)
In Android, the recommended behavior is as such:
- The Back button returns you to a previous "screen". You don't always need to start a new Activity to create a new "screen", if you manage your own "sub-screen", you should override your Back button so it returns to the previous "sub-screen".
- User multitasks and when memory-constrained, the OS may kill your application. You should make sure users do not lose their unsaved work (e.g. partially filled forms) if the OS kills your application, your application should restore whatever the user is doing as if it's never killed when the user returns to your application. Assume that the user may go away at any time to do another activity (e.g. an urgent email notification comes up, and the user abandons your application to read the email), and behave appropriately.
- There is an UI design guideline regarding your question: http://developer.android.com/guide/practices/ui_guidelines/activity_task_design.html
Ironically, even Google admits that not all native applications behave this way. Some of the native applications violates the guideline due to conscious design decisions, while some just because historical reasons.
I would recommend this books. http://commonsware.com/
If you are a Java beginner you should maybe consider learning Java first. Good books would be Head First Java or Thinking in Java for example.
After reading those books I'd recommend trying out online tutorials as you can learn a lot of things which are not that good whereas the quality of the books is great!