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

前端 未结 7 1252
借酒劲吻你
借酒劲吻你 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:47

    Here's convenience method so you don't need to write it yourself:

    protected boolean isStartedByLauncher() {
        if (getIntent() == null) {
            return false;
        }
        boolean isActionMain = Intent.ACTION_MAIN.equals(getIntent().getAction());
        Set<String> categories = getIntent().getCategories();
        boolean isCategoryLauncher = categories != null && categories.contains(Intent.CATEGORY_LAUNCHER);
        return isActionMain && isCategoryLauncher;
    }
    
    0 讨论(0)
提交回复
热议问题