Hari Krishnan
Hari Krishnan

Reputation: 6312

How to detect resume state of application instead of activity?

I have two situations

  1. A main activity from which I start another activities and return back to the main activity from this activity.
  2. My whole application is in the background and I'm returning to the main activity.

How could I identify these two situations separately? I think onRestart and onResume methods can't help me because both these methods will be called on both situation.

Upvotes: 0

Views: 703

Answers (1)

Harlan
Harlan

Reputation: 847

To identify the two situation in your question, you can follow these steps:

  1. In you main activity, use startActivityForResult to start other acitivities with requestCode >= 0
  2. override onActivityResult method in main activity to handle the event when you return back from other activity.
  3. call setResult in other activity before you want to return to the main acitivty.

your second situation would not trigger onAcvitityResult method.

Upvotes: 1

Related Questions