Notification Click not launch the given Activity on Nexus Phones

后端 未结 9 977
一个人的身影
一个人的身影 2020-12-08 14:59

I am using this code to show the local notification and When notification comes then on click of notification want to launch the ListActivity but on Google nexus device

9条回答
  •  甜味超标
    2020-12-08 15:43

    Try to replace this

    notificationIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);   // To open only one activity on launch.
    PendingIntent pIntent = PendingIntent.getActivity(context, reqCode,
            notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    

    to

    notificationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);   // To open only one activity on launch.
    PendingIntent pIntent = PendingIntent.getActivity(context, reqCode, notificationIntent, Intent.FLAG_ACTIVITY_NEW_TASK);
    

    it will work for all version even with Kitkat also.

    Note : Activity will be started outside of the context of an existing activity, so you must use the Intent.FLAG_ACTIVITY_NEW_TASK launch flag in the Intent.

提交回复
热议问题