开发者

Switching between Android activities

I am working on an Android application where I would want to switch between 3 activities (say Home, Map and Photo). Right now the flow is like 'Home>Map>Photo'. I would like to allow the user to switch between these 3 activities. Say if he wants to go from Photo to Map or from Photo to Home without destroying the Photo activity. What is the best way in Android to achieve this?

I went through other answers on SO but it seems like caching the data somewhere is the only feasible way which does not break other functionality (For ex. back button).

-- Edit --

I want this to work exactly like the way TabHost works. Will appreciate any ideas about ho开发者_JAVA百科w to achieve that.


Well, you could setup a tab system, but why would you care if the Activity gets destroyed or not - Android keeps a saved instance state (in a Bundle), so when your Activity gets created again, you can go back to the original state.


Ok, so this is what I ended up doing to restore the state once the activity finishes.

  • Store all primitive variables in the SharedPreferences of the activity.
  • Store images as files.
  • Will use SQLite if needed.

I also looked at db4o android but not sure whether I'll use it.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜