Differentiating between an Activity launch from home screen or from another activity from App

前端 未结 7 1250
借酒劲吻你
借酒劲吻你 2020-12-09 03:51

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

7条回答
  •  有刺的猬
    2020-12-09 04:37

    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.

提交回复
热议问题