Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where is the bundle of onSaveInstanceState saved?

Tags:

I would like to know where the bundle "outState" of the method onSaveInstanceState(Bundle outState) is stored.

Is it stored in memory or in the device storage?

I am concerned about the security of the data which is stored in the bundle.

like image 568
Jleuleu Avatar asked Nov 11 '11 09:11

Jleuleu


People also ask

Where is Android bundle stored?

It turns out that these instance state bundles are stored in the Activity Manager service. This service is implemented under the package com.android.server.am in the Android source code.

How do you save onSaveInstanceState?

1 Answer. Show activity on this post. You can replace above with the data you want to save and then re-populate your views like RecyclerView etc with the data you saved in the savedInstance as key-value pair. Just keep in mind that the Bundle is not meant to store Large amount of data.

How do I retrieve data from savedInstanceState?

Retrieve the saved instance state data in the onCreate(Bundle savedInstanceState) method use the Bundle input parameter also. You can also retrieve the saved instance state data in the onRestoreInstanceState(Bundle savedInstanceState) method.

How to save state of fragment?

Various Android system operations can affect the state of your fragment. To ensure the user's state is saved, the Android framework automatically saves and restores the fragments and the back stack. Therefore, you need to ensure that any data in your fragment is saved and restored as well.


1 Answers

To store data only for application lifetime (ie temporarily), use the onSaveInstanceState(Bundle) activity event

This data will only be held in memory until the application is closed, the data will be available any time that this activity starts within the current lifetime of the application.

Explanation: if data is stored here by activity A then the application shows a different activity or rotates the screen (hence closing A) and then returns to A the data can be retrieved to populate the controls. However if the application is closed and opened again the data will be gone and the controls will revert to their default values.

Example of use: storing text typed in by user and selections making up an order, blog entry, message, etc...

Note:

It’s important to notice that only the Activity is destroyed and recreated, not your whole application! An Android application can consist of many Activities, Services and ContentProviders! If the application is closed (for example by pressing the “Back” Button, then all values will be gone. savedInstaceState is only there to preserve data temporary when an Activity is destroyed/recreated, not the application itself.

If you want to preserve data permanently, you need to save it either as Preferences or in a ContentProvider/database.

like image 64
user370305 Avatar answered Sep 27 '22 19:09

user370305