Starting the app from Notification remove it from recent app history

后端 未结 5 1516
逝去的感伤
逝去的感伤 2021-02-12 23:04

I have a problem in one of my apps when I start it from a notification. It never appears in the \"recent app\" list.

Without notifications, every thing works as expected

5条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-02-12 23:32

    Add the action android.intent.action.MAIN and the category android.intent.category.LAUNCHER to the specification of your activity. Having two actions and categories seem like a hack but it's actually supported by Android.

    
        
            
            
            
            
            
        
    
    

    That should add it to the recent applications list. The reason is described in the Android developer documentation:

    An intent filter of this kind causes an icon and label for the activity to be displayed in the application launcher, giving users a way to launch the activity and to return to the task that it creates any time after it has been launched.

    This second ability is important: Users must be able to leave a task and then come back to it later using this activity launcher. For this reason, the two launch modes that mark activities as always initiating a task, "singleTask" and ""singleInstance", should be used only when the activity has an ACTION_MAIN and a CATEGORY_LAUNCHER filter. Imagine, for example, what could happen if the filter is missing: An intent launches a "singleTask" activity, initiating a new task, and the user spends some time working in that task. The user then presses the Home button. The task is now sent to the background and is not visible. Now the user has no way to return to the task, because it is not represented in the application launcher.

提交回复
热议问题