tags:

views:

68

answers:

2

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 how to achieve that.

A: 

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.

xil3
Here I would be finishing the activity when the user goes to another activity or if he presses the back button. I don't know whether Android stores the bundle for the last finished activity. If that happens then I can just re-create the activity from the bundle.
Abhinav
A: 

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.

Abhinav