Resume application and stack from notification

后端 未结 8 1642
一向
一向 2020-11-22 16:04

I want to resume my app from a status bar notification in the exact same manner as when the user taps its icon in the launcher.

That is: I want the stack to be in th

8条回答
  •  一个人的身影
    2020-11-22 16:57

    THE ULTIMATE SOLUTION: Notification to restore a task rather than a specific activity?

    public class YourRootActivity extends Activity 
        {
            @Override
            protected void onCreate(Bundle savedInstanceState) 
            {
                super.onCreate(savedInstanceState);
        
                if (!isTaskRoot()) // checks if this root activity is at root, if not, we presented it from notification and we are resuming the app from previous open state
                {
                     val extras = intent.extras // do stuffs with extras.
                     finish();
                     return;
                }
                 // OtherWise start the app as usual
            }
        }
    

提交回复
热议问题