I m trying to switch between two activities . In activity 1, i have Button named GoToSecond to goto second activity. In the same way,in activity 2, have Button named GoToFirst to goto first activity.
I have used log messages in first activity .
Order I m getting when GoToSecond button is clicked is onCreate
onStart
onResume
onSaveInstance
onStop
and it switches to second activity . Now in second activity when i click button GoToFirst , first activity opens and log order in first activity is
onCreate
onStart
onResume ..
why onRestoreInstance is not getting called after onStart? even if instance is stored??
Can anyne help me?
Here is the code of first activity:
public class MainActivity extends AppCompatActivity {
EditText hello;
Button b1;
public static String TAG="Prajwal";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
hello=(EditText) findViewById(R.id.hello);
Log.d(TAG,"OnCreate counter 1");
b1=(Button) findViewById(R.id.b1);
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i=new Intent(MainActivity.this,Main2Activity.class);
startActivity(i);
}
});
I havent added log messages in code .
And second activity code is
public class Main2Activity extends AppCompatActivity {
Button b2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
b2=(Button) findViewById(R.id.b2);
b2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i=new Intent(Main2Activity.this,MainActivity.class);
startActivity(i);
}
});
Log.d(MainActivity.TAG,"Oncreate 2");
}
For example If i hv an EditText in first activity , and if i hav some text in it , I m losing that text while switching between 2nd activity to 1st activity . bcoz onCreate is called in first activity. But when i switch to landscape mode onRestoreInstance is called and i m not losing any text .