Calling startActivityOnResult () automatically calls the onPause (), onStop () and onDestroy () methods of the current activity

I start another activity by calling startActivityForResult()

, and after hitting the return button, my previous activity's onCreate Method is called, hence recreating the entire activity.

While debugging, I found that the call startActivityOnResult()

automatically calls

onPause()
onStop()
onDestroy()

      

methods of current activities. Is this the usual behavior because I read it, only calls a method onPause()

to start 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);
}

      

+3


source to share


2 answers


onPause()

and onStop()

are completely normal. These calls will be called anytime your activity no longer has a foreground input ( onPause()

) and is no longer visible ( onStop()

).



onDestroy()

should only be called if you somehow terminate your activity yourself, or perhaps if you are launching an activity in a separate app and Android needs to terminate your own app process to free up RAM.

+2


source


I am having the following problem. I solved it by removing the FLAG_ACTIVITY_NEW_TASK flag



0


source







All Articles