Reputation: 6777
How do I know if an Activity A was started from Intent:
Intent intent = new Intent(this, Activity.class);
startActivity(intent);
or due to activity lifecycle (after destroy, activity A can be created again, if it is on history applications).
Is there some way to distinguish these two ways to invoke an Activity?
Upvotes: 1
Views: 124
Reputation: 11861
So if I understood you want to check if onCreate
it's called a second time. You can achieve that by using this logic:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if(savedIntanceState != null && savedIntanceState.getBooleanExtra("FIRST_RUN", false)){
//not a first run
}
}
protected void onSaveInstanceState(Bundle outState) {
outState.putBoolean("FIRST_RUN", true);
super.onSaveInstanceState(outState);
}
Upvotes: 2
Reputation: 10859
use PutExtras()
on the Intent
Activity
check this or that or this-indirect-post
When your Activity
is Recreated it is created with a different Intent
not the Intent
that was used to spark it initially-(especially from history), so if you use extras and check in your oncreate you will be better of -(read this with regards to the not soo much indirect post)
Upvotes: 2