startActivity 在推送处理程序中不起作用

startActivity not working in push handler

我正在尝试在点击特定类型的推送通知时启动新的 activity。我扩展了 ParsePushBroadcastReceiver class(我正在使用 Parse)并覆盖了 onPushOpen 方法。

当我点击推送时,会调用以下代码:

Intent postIntent = new Intent(App.context, SinglePostActivity.class);
postIntent.putExtra(SinglePostActivity.ARG_POST_ID, postId);
context.startActivity(postIntent);

但是没有任何反应。我的 activity 在 AndroidManifest 中注册成功。如何才能成功启动 activity?

可能 App.context 导致问题。

使用 onPushOpen 方法的 Context 参数创建 Intent 并访问 startActivity Activity 方法:

Intent postIntent = new Intent(context, SinglePostActivity.class);
....
postIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(postIntent);