I'm trying to understand the difference between onPause and onStop.
I've read all the different forums but I still am not clear about the difference. I've created a simple app to try and test when which method gets called. For that I've simply placed loggers in each method.
From my trials -
- Popups do not call either method
- Switching to another activity calls both methods
- Pulling down the notification bar calls neither method
I've only seen either both methods being called in quick succession or neither getting called at all. I'm trying to find scenarios where onPause gets called but onStop doesn't.
The purpose is to understand whether defining onPause is even required. If the scenarios in which only onPause gets called are so rare, it doesn't even make sense to write separate code for onPause. Shouldn't writing onStop be sufficient?
public class LifecycleActivity extends ActionBarActivity {
@Override
protected void onDestroy() {
super.onDestroy();
Log.d("Rachit", "In Destroy Method");
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_lifecycle);
Log.d("Rachit", "In Create Method");
}
@Override
protected void onStart() {
super.onStart();
Log.d("Rachit", "In Start Method");
}
@Override
protected void onResume() {
super.onResume();
Log.d("Rachit", "In Resume Method");
}
@Override
protected void onPause() {
super.onPause();
Log.d("Rachit", "In Pause Method");
}
@Override
protected void onRestart() {
super.onRestart();
Log.d("Rachit", "In Restart Method");
}
@Override
protected void onStop() {
super.onStop();
Log.d("Rachit", "In Stop Method");
}
}