I need to know a generic way to distinguish between a call of activity from launcher and a call from another activity from inside my app, or a BACK on the activity stack
Anyone? this is bugging me for quite a while now and i need to put it to rest...
Thanks in advance JQCorreia
The intent-filter inside the activity tells Android which Activity to launch.
If both application have the same signature (meaning that both APPS are yours and signed with the same key), you can call your other app activity as follows: Intent LaunchIntent = getActivity(). getPackageManager(). getLaunchIntentForPackage(CALC_PACKAGE_NAME); startActivity(LaunchIntent);
In the onCreate of your Activity, call getIntent()
. If the Activity is started from the launcher (home screen) the values for getAction()
will be android.intent.action.MAIN
and the getCategories()
will return a set which will contain the android.intent.category.LAUNCHER category.
If the activity is started from elsewhere these values may be null
.
In addition to @advantej's answer, you can extend each start-call to that activity adding an extra to the starting intent (e.g. intent.putExtra("caller", this.getClass().getSimpleName()
);
In the activity's onCreate
method you can check then what @advantej suggests.
If the initiator is not the home-screen icon, than you can check further if the intent.hasExtra("caller")
returns true, and if so, what is it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With