0

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.

Marat
  • 6,142
  • 6
  • 39
  • 67
Hari Krishnan
  • 5,992
  • 9
  • 37
  • 55
  • This link may be helpful for you: http://stackoverflow.com/questions/5447912/android-detecting-application-launch-from-home-or-history#14941514 – jujka Jul 09 '16 at 15:18
  • create base activity and inherit from that on all activities, override onPause and onResume in baseActivity, in onPause run one handle with 1 second postDelay, if on resume called before running handler code, stop handler. in handle code change one boolean value that application goes to background. in onResume or any where else check that – Shayan Pourvatan Jul 09 '16 at 17:22

1 Answers1

1

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.

Harlan
  • 847
  • 5
  • 15