Saving intent data in android
I am creating a simple poll app in android studio. I have multiple intentions and I run each one when the Next buttons are clicked. I also have a back button that takes the user to the previous intent if they want to change the answer to a question. When I go ahead again, none of the answers are saved. How can I get answers to all user responses?
source to share
You can override two methods in your actions:
public void onSaveInstanceState(Bundle savedInstanceState);
public void onRestoreInstanceState(Bundle savedInstanceState);
As you can see, you have access to the "savedInstanceState" Bundle. If the user terminates the onSaveInstanceState () action is called and you have the option to save the data you want to restore later.
The onRestoreInstanceState () method is only called if you have saved information in onSaveInstanceState () and offers you the option to restore this data. It provides a collection that contains the same data that you saved in the data during onSaveInstanceState ().
The package is basically a list of key values. To store a string, for example, you simply call the putString () method - the package method:
savedInstanceState.putString("myKey", "Hello World");
There are many types of data that can be stored in a bundle (in general, every class that implements the Parcelable interface can be stored in a bundle).
Additional Information:
http://developer.android.com/training/basics/activity-lifecycle/recreating.html http://developer.android.com/reference/android/os/Bundle.html
source to share
When your actions are recreated, they receive an onCreate (Bundle) callback . Whatever you save in onSaveInstanceState (Bundle) will appear in the Bundle.
source to share