0

I have 2 major activity in my project Connect+Details and Menu. After I switch between the first activity to the second everything goes well. the problem start in returning back from 'Menu' to 'Connect+Details'.

when I use the back key to switch between the second activity and go back to the first everything goes well.

problem start when I use this code:

Intent myIntent = new Intent(Menu.this, ConnectActivity.class);
startActivity(myIntent);

I do go back to 'Connect+Details' but every detail in that activity is lost.

my question is simple, how can i go back to previews activity and still have the details used in that activity.

Edit: the same thing goes even when I am in the 4th, 5th activity so finish() didn't help me.

2 Answers2

0

You probably want to either save your data in SharedPreferences or in a database then use the saved data to repopulate your Activity. You can use SharedPreferences to save a key/value pair when you leave your Connect Activity and this will persist even if your app is closed.

If there will be a lot of data stored then you may consider using an SQLite DB. This can be a little trickier to set up and use but may be worth it if you are storing a lot of data...especially if its for different users.

Both of these options will persist your data when you leave the Activity or the program. You could also use a static Array but one of the first two options will probably be better for you.

The Storage Options Docs has some decent examples to get you started, especially if you decide that Shared Preferences will work for you.

Edit

Unless something has changed, you can't store serializable objects in SharedPreferences. But Here is a SO link that discusses saving them to a file and reading from there. Maybe this will help you.

Community
  • 1
  • 1
codeMagic
  • 44,549
  • 13
  • 77
  • 93
0

Don't use Intent to move from 'Menu' to 'Connect+Details' instead call finish(); from it

Only use intent in first class to move to second ie;'Connect+Details' to 'Menu'

Don't call finish() in Connect+Details

Lundin
  • 195,001
  • 40
  • 254
  • 396
Viswanath Lekshmanan
  • 9,945
  • 1
  • 40
  • 64
  • OK thank you, but what do I do if I want to go from an activity that comes after "menu"? – user2013881 Apr 01 '13 at 18:50
  • I dont get u,u need to move from Connect+Details->Menu and Menu<-Connect+Details, now do u need to move from Menu -> otherclass? is it – Viswanath Lekshmanan Apr 01 '13 at 18:55
  • connect+details -> menu -> add new client -> update client -> connect+details. that is my loop the major thing is that in 'connect+details there is properties of my connection to the server. that connection must not be altered and can not be renew as long as the app is running – user2013881 Apr 02 '13 at 11:35