Intent to resume a previously paused activity (Called from a Notification)

后端 未结 5 1495
自闭症患者
自闭症患者 2020-12-25 15:05

I\'m developing an app which shows a notification to the user. The notification\'s objective is to make it easy to the user to return to the activity when the user is in ano

5条回答
  •  天涯浪人
    2020-12-25 15:12

    I found out how to do it. I added the following code:

    notifyIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    

    Now my code looks like this:

        notification = new Notification(R.drawable.icon,
                "Notify", System.currentTimeMillis());
        notification.setLatestEventInfo(this, "App name",
                "App message", PendingIntent.getActivity(this,
                        0, new Intent(this, Main.class)
                                .setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
                                        | Intent.FLAG_ACTIVITY_SINGLE_TOP),
                        PendingIntent.FLAG_CANCEL_CURRENT));
        notification.flags |= Notification.FLAG_ONGOING_EVENT;
    

提交回复
热议问题