tags:

views:

33

answers:

1

hi,

I have set a value in spinner , from activity-1. now i am traversing to activity-2 and again coming back to activity-1, i am not getting the updated spinner value which i have selected previously but i am getting default value(value at index 1) of spinner .

+1  A: 

An Activity that becomes inactive (invisible to a user) can be destroyed by the system in case of lacking resources. To keep values between Activity runs you need to save your state using Bundles. If you look closely to Activity::onCreate method you can see it has a parameter:

protected void onCreate (Bundle savedInstanceState)

So, eg in method onPause() you save your desired values and when Activity is recreated - load them.

Android documentation contains a chapter how to save states between Activity runs.

Marcin Gil