Dare Obasanjo
Dare Obasanjo

Reputation: 695

How do I determine if an activity is being launched from a back navigation versus being launched by the user in Android?

The home screen of my app needs to have different behavior when the app is being launched from outside the app versus when a back navigation occurs. For example, imagine an Android Twitter client which on launch tries to get your updated feed but when you click on an item to hit its detail page and hit back, the screen doesn't reload new feeds but is instead where you left from.

So far I've tried looking at the calling package property but this hasn't helped since it seems to be null both when app is launched by the user for the first time or when I hit back from a detail page.

Upvotes: 0

Views: 74

Answers (1)

Sushil
Sushil

Reputation: 8478

When user launches it first time, onCreate() then onresume() will be called for sure. When navigating back and getting your activity from backstack, just onResume will be called.

Also if you activity has singleTop set, then you can look into onNewIntent() which will be called when you navigate back to your activity from other screens.

So, the solution I can suggest you is to set singleTop for your activity. Then while navigating back using onNewIntent(). For 1st time launch onCreate() will be called.

Sorry if I could not understand your question well..

Upvotes: 1

Related Questions