0

I am starting an activity called ChildActivity from ParentActivity as startActivityForResult(). Now, in the child activity I have different functionalities which require restarting the activity(ChildActivity). I am restarting the activity like

Intent intent = getIntent();
startActivityForResult(intent, CODE);
finish();

And also added in ChildActivity

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if(resultCode == RESULT_OK && requestCode == CODE)
        super.onActivityResult(requestCode, resultCode, data);
}

But anyway I am getting only one result to the ParentActivity with RESULT_CANCELLED when the ChildActivity restarts. I am unable to receive any further results after the ChildActivity restarts.

How can I get the further results.

Regards, pradeep_ch.

pradeep_ch
  • 124
  • 8
  • For what purpose you need to restart activity? – Vikalp Patel May 26 '14 at 08:06
  • After calling startActivityForResult from the child Activity, it's the parent of the one already opened, so onActivityResult of finished Activity 'll be called. My advice is to not to restart the activity. That's not the Android way;) – Albert Sadowski May 26 '14 at 08:07
  • Basically the ChildActivity is for recording video and it has flip camera option, when the user clicks on flip_camera button switching camera and when the camera switches need to restart activity. – pradeep_ch May 26 '14 at 08:10
  • @pradeep_ch : Have look in here for switching camera w/o restarting your activity http://stackoverflow.com/questions/16765527/android-switch-camera-when-button-clicked – Vikalp Patel May 26 '14 at 08:13

2 Answers2

1

If you really need to restart this Activity, restart it from the parent Activity. In the onActivityResult, you can handle the restart.

Albert Sadowski
  • 642
  • 5
  • 8
0

probably you do mean restarting an activity is calling onResume in android way. just add a flag there what will the activity will load if it has that kind of flag. just call onResume() anywhere if you want to reload the activity.

@Override
protected void onResume() {
    super.onResume();

    if (flag == SOMETHING) {
        // do something or load views
    } else {
        // do something or load views
    }
}
Samoka
  • 1,283
  • 2
  • 12
  • 23