Reputation: 201
In my Application when on pressing on the back button returning to previous activity, the variables are still set up and containing values, my question is how can I reset all variables in any activity, so to act when first launched?
If this helps, i'm having an app that contains three activities;
In Activity 1: am putting Bundle.putExtras()
some string to send to the next activity ...
In Activity 2: also putting some strings in a bundle and sends it to Activity 3 ...
Upvotes: 0
Views: 2421
Reputation: 1315
You can finish()
your current activity after you call
your second activity
. This will clean variable in your ex activity.
Upvotes: 0
Reputation: 509
Just initialize all variables on the onResume() method. That way, every time your activity comes into play, your data is wiped out.
Upvotes: -1
Reputation: 4028
Your non-static variables will be cleared and be reset to their defaults when you go back from your Activity
.
Your static variable can be reset in the onDestroy()
method of your Activity
, although doing that defeats the purpose of making them static in the first place.
EDIT: I see you were talking about the previous Activity
. In this case, just override the onResume()
of your previous Activity
to do the clearing of variables, although I fail to see why you would need to do that.
Upvotes: 2