0

This is a very specific need I have. And there are reasons for it. The question is as simple as stated in the title: I have many activities in my project. But for activities DogActivity and CatActivity. I would like when DogActivity starts CatActivity, for CatActivity to see if as if called through onActivityResult as opposed to onCreate. Is this possible? Any example code?

EDIT

Two of the lifecycle methods of an activity that can be overridden are onCreate and onActivityResult. If CatActivity were to start DogActivity with startActivityForResult, then naturally when DogActivity finishes, CatActivity's onActivityResult method is called.

In my scenario, CatActivity is NOT the one that started DocActivity; on the contrary, I need DogActivity to start CatActivity. But when DogActivity starts CatActivity, I would have to have CatActivity behave as though DogActivity were returning to CatActivity's onActivityResult. So instead of going through onCreate, I want it to go through onActivityResult. Hence my question: is that possible?

Cote Mounyo
  • 13,817
  • 23
  • 66
  • 87

1 Answers1

2

Yes, just add an Extra when calling the intent.

Intent intent = new Intent(context, class);
intent.putExtra("from_activity_result", true);

And then in the receiving Activity, you can call:

getIntent().getBooleanExtra("from_activity_result", false);

If it's true, then you know it came from the onActivityResult method. If not, you know it didn't.

Cruceo
  • 6,763
  • 2
  • 31
  • 52
  • Please see my edit section. I don't think you understood the question the first time. – Cote Mounyo Sep 08 '13 at 00:08
  • No, that's exactly what it's for. If getIntent().getBooleanExtra("from_activity_result", false) == false, then it means it did NOT come from CatActivity, and DogActivity must start it. Unless your question is you want onCreate NOT to be called, which is absolutely NOT possible. – Cruceo Sep 09 '13 at 14:44