0

i switch to next screen and then comes back to the original and wants to pick up where i left off , save and restore data.In Activity 1:i have more than 10 buttons i can select and unselect button,if go to next screen and if i come back it should not reload,it should show me where i leftoff,

    up1 = (Button) findViewById(R.id.adultup1);
    up1.setOnClickListener(new View.OnClickListener() {

        public void onClick(View view) {
            if (upt1 == 0) {
                up1.setBackgroundResource(R.drawable.adultup1);
                upt1 = 1;
            } else {
                up1.setBackgroundResource(R.drawable.adultup1_pressed);
                upt1 = 0;
            }
        }
    });  submit = (ImageButton) findViewById(R.id.next);
    submit.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            TabFunctionality.setFirstTabFunctionality(TabFunctionality.FIRST_TAB, 1);
            Intent intent = new Intent(AdultTeeth.this, MainScreen.class);
            intent.putExtra("TEXT", view);
            startActivity(intent);
            finish();

        }
    });
}
user828948
  • 151
  • 1
  • 3
  • 8

2 Answers2

0

I am not sure the whole picture of your activities as you just post a part of the code. I can tell you now is you could use startActivityForResult() instead of startActivity(). StartActivity() and finish() will close Activity 1.

And you could get anything result of Activity 2 from onActivityResult() in Activity 1.

Terence Lui
  • 2,778
  • 1
  • 18
  • 17
0

override protected void onSaveInstanceState(Bundle outState){} and save all button states here and put it in the bundle. and while creating or resuming Activity get these values and restore your state..

ngesh
  • 13,398
  • 4
  • 44
  • 60
  • how to store the button states?pls help me to do this? – user828948 Oct 03 '11 at 10:10
  • You told to store button states right for example dwn16 = (Button) findViewById(R.id.adultdwn16); dwn16.setOnClickListener(new View.OnClickListener() { public void onClick(View view) if(dwnt16==0){dwn16.setBackgroundResource(R.drawable.adultdwn16); dwnt16=1;}else{ dwn16.setBackgroundResource(R.drawable.adultdwn16_pressed);dwnt16=0; }}}); how to store each button state – user828948 Oct 03 '11 at 10:17
  • @user828948.. rea this, http://stackoverflow.com/questions/151777/how-do-i-save-an-android-applications-stated – ngesh Oct 03 '11 at 10:30
  • i understant that.but can i have some more detailed idea? – user828948 Oct 03 '11 at 10:51
  • actually i want to store these in one class and i need to acess – user828948 Oct 03 '11 at 10:52