user1071762
user1071762

Reputation: 685

android restore state of edittext after returning to the activity

I am beginner to android developing and I am dealing with a probably simply solvable problem. I have a Main activity which is a menu and the user can click on of the items on menu. Then a new Activity is started using startActivity(new Intent("com.example.test.FIRSTITEM")); this activity starts a layout with few edittexts. I write something into them. Then to go back to the MainActivity (where the menu is) one have to press back button. And now I want the behaviour that if I return to the Activity with edittexts, I want them to be in the same state - meaning the content wouldn't be cleared. I've searched a lot and tried all options of android:launchMode="" (singleTop, singleInstance, singleTask). I've also tried to use flags when starting new intent from MainActivity: startActivity(new Intent("com.example.test.FIRSTITEM").setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP)) I've tried using onSavedInstanceState(Bundle bundle) but this one is never called when pressing back button (probably because the activity isn't really finished)

I am sure the answer is simple but I can't seem to find it. I must be missing some logic of how activities work. Thank you for your help in advance.

Upvotes: 1

Views: 1681

Answers (1)

Jagdeep Singh
Jagdeep Singh

Reputation: 1210

I think this this could help you out.You can use onsaveinstancestate() and onrestoreinstancestate().

Upvotes: 1

Related Questions