Bundle is a container for all the information you want to keep. You use put * functions to insert data into it. Here's a short list (there are more) of put functions that you can use to store data in the Bundle .
putString putBoolean putByte putChar putFloat putLong putShort putParcelable (used for objects but they must implement Parcelable)
In your onCreate function onCreate this Bundle returned to the program. The best way to check if the application is restarting or starting for the first time:
if (savedInstanceState != null) {
To return data, use the get * functions in the same way as the put * functions. Data is stored as a name-value pair. It looks like a hash map. You provide the key and value, and then when you want to return the value, you give the key, and the function gets the value. Here is a brief example.
@Override public void onSaveInstanceState(Bundle outState) { outState.putString("message", "This is my message to be reloaded"); super.onSaveInstanceState(outState); } @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (savedInstanceState != null) { String message = savedInstanceState.getString("message"); Toast.makeText(this, message, Toast.LENGTH_LONG).show(); } }
Your saved message will be fried on the screen. Hope this helps.
Spidy Jun 29 '11 at 19:00 2011-06-29 19:00
source share