-1

How do I save the way my Activity is so when closed with the back button and resumed it will be the same way it was when closed.

this is my Activity code:

public class Levels extends Activity{

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setTheme(android.R.style.Theme_NoTitleBar_Fullscreen);
    setContentView(R.layout.levels);

    final EditText anstext1 = (EditText) findViewById(R.id.anstext1);
    Button button1 = (Button) findViewById(R.id.button1);

    button1.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {   
             String result = anstext1.getText().toString();
             if(result.equals("they"))
                 setContentView(R.layout.social);
             else 
               Toast.makeText(getApplicationContext(), "Wrong", Toast.LENGTH_LONG).show();
        }
    });
    }

}

user2192418
  • 49
  • 1
  • 5

3 Answers3

1

In the onSaveInstanceState() method you can add your data into the bundle and then when the onCreate() is called you can grab those previous values from the bundle.

ElefantPhace
  • 3,806
  • 3
  • 20
  • 36
JoxTraex
  • 13,423
  • 6
  • 32
  • 45
0

Use onSaveInstanceState like explained here

ElefantPhace
  • 3,806
  • 3
  • 20
  • 36
Arun C
  • 9,035
  • 2
  • 28
  • 42
-1

You can use onResume to restore the resources, and when Activity is dead, you can use properties to save resources and roll back.

ElefantPhace
  • 3,806
  • 3
  • 20
  • 36