resuming an activity from a notification

前端 未结 7 2189
刺人心
刺人心 2020-11-30 12:24

I have a notification in the status bar for my app:

    Notification notification = new Notification(R.drawable.icon, null, System.currentTimeMillis());

            


        
7条回答
  •  醉话见心
    2020-11-30 12:36

    I was having a similar problem and the proper way to handle this is to use the flags: Intent.FLAG_ACTIVITY_CLEAR_TOP and Intent.FLAG_ACTIVITY_SINGLE_TOP like so

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

    From the documentation this will:

    FLAG_ACTIVITY_CLEAR_TOP

    If set, and the activity being launched is already running in the current task, then instead of launching a new instance of that activity, all of the other activities on top of it will be closed and this Intent will be delivered to the (now on top) old activity as a new Intent.

    FLAG_ACTIVITY_SINGLE_TOP

    If set, the activity will not be launched if it is already running at the top of the history stack.

提交回复
热议问题