How to open last activity from notification status bar?

前端 未结 4 944
庸人自扰
庸人自扰 2020-12-16 06:35

I want to open last started activity by tapping on the notification in status bar. Suppose I start an Activity A (main activity of my app), this activity sends a notificatio

4条回答
  •  天涯浪人
    2020-12-16 07:21

    Have you tried this:

    final Intent intent = new Intent(context, YourActivity.class)
    intent.setAction(Intent.ACTION_MAIN);
    intent.addCategory(Intent.CATEGORY_LAUNCHER);
    

    The above codes instruct Android to open the last activity, whether it's the main activity or a preference activity [that's currently in the foreground] that you used to create/launch the icon in the notification bar in the first place.

    ACTION_MAIN and CATEGORY_LAUNCHER refer to and directives respectively in your AndroidManifest.xml file.

提交回复
热议问题