Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: How to ignore or disable savedInstanceState?

I want to ignore or disable savedInstanceState so that the state of current activity won't save when I go to the next activity.

public void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
like image 877
Kris Avatar asked Jun 01 '11 08:06

Kris


People also ask

What is savedInstanceState in Android?

The savedInstanceState is a reference to a Bundle object that is passed into the onCreate method of every Android Activity. Activities have the ability, under special circumstances, to restore themselves to a previous state using the data stored in this bundle.

What does Super onCreate savedInstanceState do?

By calling super. onCreate(savedInstanceState); , you tell the Dalvik VM to run your code in addition to the existing code in the onCreate() of the parent class. If you leave out this line, then only your code is run. The existing code is ignored completely.

What is the use of onSaveInstanceState?

In cases where the UI data to preserve is simple and lightweight, you might use onSaveInstanceState() alone to preserve your state data. Note: You can provide access to a saved state in ViewModel objects with the Saved State module for ViewModel.


2 Answers

Just this:

public void onCreate(Bundle savedInstanceState){
    super.onCreate(null);
like image 131
Vladimir Ivanov Avatar answered Sep 28 '22 18:09

Vladimir Ivanov


Or this:

@Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        outState.clear();
    }
like image 45
R00We Avatar answered Sep 28 '22 18:09

R00We