I have an Activity A
with 2 tabs and each tab have its own Activity (B and C)
. Activity B
and Activity C
each have 2 text fields . I want to save value of these text field in SharedPreferences
when user changes tabs.
How can I do this?
I have an Activity A
with 2 tabs and each tab have its own Activity (B and C)
. Activity B
and Activity C
each have 2 text fields . I want to save value of these text field in SharedPreferences
when user changes tabs.
How can I do this?
What you probably want is save your activity state in onSaveInstanceState
instead, like this:
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putString(MY_KEY, myStringValue);
// ...
}
And then in onCreate:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// other stuff...
if(savedInstanceState != null) {
myStringValue = savedInstanceState.getString(MY_KEY);
}
}