whistle
whistle

Reputation: 11

How to keep the value in the activity after coming back from another activity

I created activity A > B > C. Activity A pass an intent to B that will determine the value on B ListView. The problem is that when I press the back button on C, the previous list on B is no longer there. How do I keep the list value on B when the user press back button on C?

Upvotes: 1

Views: 72

Answers (1)

Surendra Shrestha
Surendra Shrestha

Reputation: 1080

Use a static list variable to store/populate the list data. You can populate this list on activity A and use on activity B and since this variable will remain through entire android life cycle the list on activity B should not be affected when returning from activity C.

public class ActivityA extends Activity{
//Inside Activity A
public static final List<MODEL> DATA_LIST = new ArrayList<MODEL>(); //here MODEL may be any type of object as required
//...
}

To use this variable on Activity B simply use ActivityA.DATA_LIST to reference to the list variable.

Upvotes: 1

Related Questions