【发布时间】:2014-05-14 17:02:18
【问题描述】:
我有一个处理推送通知所需的 Sencha Touch + Phonegap 应用程序。当应用未运行,或在后台,通知到达时,用户点击通知,应用打开,并正确导航到 Sencha Touch 应用中的相应页面。
问题是当应用程序已经在前台时。
我也在这个应用程序中使用 Urbanairship 图书馆。在 Urbanairship 配置中,我必须指定当用户点击通知时应该打开的活动。
并且配置如下:
@覆盖 公共无效 onReceive(上下文上下文,意图意图){ super.onReceive(上下文,意图); if (intent.getAction().equals( “com.urbanairship.push.NOTIFICATION_OPENED”)){ 意图 openIntent = new Intent(context, MainActivity.class); openIntent.setAction(intent.getAction()); openIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); openIntent.putExtra("where", "push"); openIntent.putExtra("数据", intent.getExtras()); context.startActivity(openIntent); } }现在,如果我将标志指定为 NEW_TASK,它将打开应用程序的另一个实例,该实例再次重新加载所有内容。然后会去相应的页面处理通知。
如果我不使用 NEW_TASK 标志,应用程序会崩溃,因为它是从非活动上下文中调用的。
如果应用程序已经在前台,它应该如何设置以便我不会创建应用程序的新实例?
【问题讨论】:
标签: android cordova sencha-touch-2 android-notifications urbanairship.com