单击推送通知时的活动(Android)

时间:2016-06-09 16:35:24

标签: android notifications backendless

我正在使用来自后端的推送通知,我可以收到通知,但是当我收到推送通知并在应用栏中点击它时,它会自动将我重定向到主要活动。

当我点击推送通知时,我希望它重定向到打开另一个活动。

我搜索了这个问题,发现我必须在我要打开的活动的Android Mainfest文件中添加以下行。

<activity android:name=".ShowMessage">

<intent-filter>

<action android:name="com.example.user.notificationfromc.MESSAGE"/>

<category android:name="android.intent.category.DEFAULT"/>

</intent-filter>

</activity>

(com.example.user.notificationfromc。)是我的包名

(ShowMessage)是我要打开的活动。

但它不起作用。

1 个答案:

答案 0 :(得分:0)

试试这个。

Intent notificationIntent = new Intent(context, YourActivity.class);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP|Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
yourNotification.setLatestEventInfo(context, title, message, intent);