I am starting another activity by calling startActivityForResult() and after pressing back button my previous activity’s onCreate Method is called hence recreating the whole activity.
On debugging I found that calling startActivityOnResult() automatically calls
onPause()
onStop()
onDestroy()
methods of current activity. Is it normal behaviour because i had read it calls only onPause() method on starting another activity.
This is my code:
@Override
public void onResume() {
super.onResume();
}
@Override
public void onPause() {
super.onPause();
}
@Override
public void onStop() {
super.onStop();
}
@Override
public void onDestroy() {
super.onDestroy();
}
public void showScore(View view) {
Intent i = new Intent(StartMultipleChoiceActivity.this, ScoreActivity.class);
i.putExtra("blockPosition", blockPosition);
int itemVisited=submittedAnswers.size();
i.putExtra("itemVisited", itemVisited);
int itemCorrect=correctAnswers.size();
i.putExtra("itemCorrect", itemCorrect);
startActivityForResult(i,1);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
}
onPause()andonStop()are perfectly normal. Those will be called any time your activity no longer has foreground input (onPause()) and no longer is visible (onStop()).onDestroy()should only be called if you are somehow finishing the activity yourself, or perhaps if you are launching an activity in a separate app and Android needs to terminate your own app’s process to free up RAM.