Application Level onResume Android

前端 未结 4 837
粉色の甜心
粉色の甜心 2021-01-12 03:54

Problem

The idea is very simple. Whenever an user comes back to my app from the Recents I want to show a simple dialog prompting with the password.<

4条回答
  •  无人及你
    2021-01-12 04:12

    You could try with this flag FLAG_ACTIVITY_LAUNCHER_FROM _HISTORY:

    if((getIntent().getFlags() & Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY )!=0){
        Log.d(TAG, "Called from history");
        //clear flag from history
        Intent intent = getIntent().setFlags( getIntent().getFlags() & (~ Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY));
        setIntent(intent);
    }
    

    Source : Android - detecting application launch from home or history

    When "A" Activity is start from recent, this flag is present. Now this flag will be also present if "A" activity call "B" activity and on "B" user press back. So you have to check flag and when you detect it you have clear intent by removing this flag, source: Remove a Paint Flag in Android

提交回复
热议问题