I have a problem with the lifecycle of my android activity. When I press the button "home", the function onDestroy() is calling. I have test with a simple hello world and Toast on callback function.
My code :
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toast.makeText(getApplicationContext(), "onCreate", Toast.LENGTH_SHORT).show();
}
@Override
protected void onRestart(){
super.onRestart();
Toast.makeText(getApplicationContext(), "onRestart", Toast.LENGTH_SHORT).show();
}
@Override
protected void onStart(){
super.onStart();
Toast.makeText(getApplicationContext(), "onStart", Toast.LENGTH_SHORT).show();
}
@Override
protected void onResume(){
super.onResume();
Toast.makeText(getApplicationContext(), "onResume", Toast.LENGTH_SHORT).show();
}
@Override
protected void onStop(){
super.onStop();
Toast.makeText(getApplicationContext(), "onStop", Toast.LENGTH_SHORT).show();
}
@Override
protected void onDestroy(){
super.onDestroy();
Toast.makeText(getApplicationContext(), "onDestroy", Toast.LENGTH_SHORT).show();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
EDIT : When I run my application, I have the toast "onCreate", "onState" then "onResume. If I press "home" buton I see the toast "onStop". If I return on my application I have the toast "onStart" and "onResume". But when I run my application on my real device (Samsung GT-P3110), I have the toast "onCreate", "onState" then "onResume. If I press "home" buton I see the toast "onStop" and "onDestroy". (My application is alway visible on the list of running application) If I return on the application, it see "onCreate" -> onState" -> "onResume" like it completly restart.
I don't understand. Can you enlighten me please ?