开发者

Android Navigation - How is it done?

OK sorry this is a bit of a "stupid" question.

Currently I am developing an application with a number of views and XML files. If I click certain buttons the view changes etc.

BUT, I want it like stack. So if you go to Page 2, pressing the back button goes back to Page 1. Currently the back button destroys the activity and the application closes.

The only thing I can think of is to have states, so if the back button is pressed, set the view to State X, but I am not sure if this is the "correct programming technique开发者_C百科" for Android.

Another thought was to have multiple Activities, so when a button is pressed, a new Activity is created on top of the old one. But this seems inefficient and stupid.

TIA


Yes, you want multiple Activities.

Activities and Intents have a lot of built-in knowledge about the back stack and make it easy to do just what you're describing while providing the user with a coherent experience.

Perhaps you could describe a bit more why you think this would be efficient for your application? Are you creating hundreds of Activities programmatically?

Edit - if you're coming from another mobile platform, where application parts are more tightly bound together, you might try thinking of Android apps as being more like web pages. The most common way to share information is via the query string (Intent) and the back button works because your are arriving at a new page (Activity) for each navigation.


The Widget Sample code, 'Wiktionary' on the android sdk site has some sample code for this in the LookupActivity.java file.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜