sk1ll3r
sk1ll3r

Reputation: 295

How to properly save data across Activities. savedInstanceState always appears to be null

I have 2 activities A and B.

  1. I call activity B from activity A using startActivity(B);
  2. I do some operations in B and call back activity A using startActivity(A);

I have noticed that instance variables in class A are cleared (reinitialized). Is using onSaveInstanceState(Bundle) a correct way to save these variables before A gets stopped?

In my onCreate(Bundle savedInstanceState) method of class A, I try to retrieve the data previously saved by onSaveInstanceState(Bundle). However the variable savedInstanceState is always null and I can't retrieve any data.

Upvotes: 0

Views: 739

Answers (1)

Chopin
Chopin

Reputation: 1452

If you want to return to your previous activity, you must call finish() on activity B, and then intercept it in activity A with onActivityResult().

Is that what you tried to accomplish?

Upvotes: 3

Related Questions