简体   繁体   中英

How to know why onStart() is called

My question is simple, how can i know if the onStart() method got called because my activity got created or because it got started by another activity through an intent?

I guess its not specifically the onStart() method but any of the activity lifecycle methods that gets called when creating an activity. Thanks.

use an extra intent for checking whenever your activity got created or got started by another activity by intent :

public static final EX_INFO = "from_another";
private boolean isFromAnotherActivity = false;

and when you start from another activity by intent, just pass the intent with:

intent.putExtra(EX_INFO, true)

read the info from your onStart method

Intent intent = getExtraIntent();
isFromAnotherActivity = intent.getBooleanExtra(EX_INFO, false);

onCreate-> onStart-> onResume. Genrally this process is followed when an Activity is Created. If you want to get notified that your Activity is called by an Intent, pass any variable using putExtra from calling activity and then check whether it has some value in getExtra in Called Activity.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM