Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Save a Activity in Android When moved to another Activity [duplicate]

Tags:

android

Possible Duplicate:
How do I save an Android application's state?

I'm currently working an application that has the following behavior : i am using 2 Edittext and there are some value which i type in it and when i press the button it will move on to the next page or activity ,But the problem is here when i return back to activity i dont find the values in edittext PLease help me .. Please let me know the code ... Thanks in Advance....

This is my code....

public class TestsampleActivity extends Activity 
{
        Button b1,b2;
        TextView t1;
        EditText e1;

        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) 
        {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);

            b1= (Button)findViewById(R.id.btn1);
            b2= (Button)findViewById(R.id.btn2);
            t1=(TextView)findViewById(R.id.tv1);
            e1=(EditText)findViewById(R.id.et1);


            b1.setOnClickListener(new Button.OnClickListener() 
            {   
                 public void onClick (View v){ add(); }
            });

            b2.setOnClickListener(new Button.OnClickListener() 
            { 
                 public void onClick (View v){ del(); }
            });
       }
       public void add()
       {
            String s1= e1.getText().toString();
            Intent intent=new Intent(this,next.class);
            intent.putExtra("name",s1);
            startActivity(intent);


            /* String s1= e1.getText().toString();
            //t1.append(s1);
            t1.setText(s1);
            */
       }
       public void del()
       {             
           e1.setText("");
           t1.setText("");
       }
}
like image 921
Nikhil Virupakshi Avatar asked Oct 31 '11 05:10

Nikhil Virupakshi


1 Answers

You must override the onSaveInstanceState(Bundle b) to save your data before loading the new activity.

Also you must restore overriding the onRestoreInstanceState and getting the values back...

you can se more information here:

Saving Android Activity state using Save Instance State

or

http://developer.android.com/reference/android/app/Activity.html#onSaveInstanceState(android.os.Bundle)

like image 148
Jordi Coscolla Avatar answered Oct 22 '22 04:10

Jordi Coscolla