【问题标题】:IBM Mobilefirst : App gets restarted when I click on the NotificationIBM Mobilefirst:单击通知时应用程序重新启动
【发布时间】:2016-10-05 07:23:55
【问题描述】:

我正在开发集成 MFP 的 android 本机应用程序。 我已经实现了 MFP 推送通知,它工作正常。我收到通知。但是当我单击通知时,我的应用程序会重新启动。

实际的问题是我在启动应用程序时启动了一个启动活动,我正在初始化我的所有 MFP 内容并终止此活动,使应用程序进入登录活动。

在我的清单文件中,我将接收器定义如下。

<activity
            android:name="SplashActivity"
            android:theme="@style/AppTheme.NoActionBar">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
            <intent-filter>
            <action android:name="com.mypackage.app_name.NOTIFICATION" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
        </activity>

接收器在我的启动活动中定义,但我正在完成此活动并进入登录活动,然后从登录到其他活动。现在,每次应用启动时都只会调用一次启动活动。

因此,当我单击通知时,它会杀死其他活动并再次启动启动活动,因为它被要求仅在启动活动中接收。

所以有人可以告诉我如何设计我的应用程序,以便在我进行应用程序的任何活动时收到通知(它不应该启动启动活动,而是应该在应用程序的同一活动上已打开,并调用 onrecieve 消息方法)..

请提出建议。

我之前问过类似类型的问题,但后来可以找到问题,所以我发布了这个问题,并附有实际问题寻求解决方案。 Mobilefirst PushNotification: On using wl_anonymousUserRealm at server, app is not calling onReceive method on clicking notification

【问题讨论】:

    标签: android push-notification google-cloud-messaging ibm-mobilefirst


    【解决方案1】:

    Setting up a GCM client in Android 和 Receiving downstream messages 是您将在您的场景中寻找的很好的参考。

    您必须定义接收消息所需的 GCM 接收器和服务。这将极大地帮助您在任何 Activity 中接收消息(因为 Service 不需要任何 UI,而 BroadcastReceiver 将有助于 CPU 处于唤醒状态,因此侦听器服务将完成其任务)。

    希望这会有所帮助!

    【讨论】:

    • 感谢您的回复。但我想了解如何使用 Mobilefirst SDK。如果您对 Mobilefirst 有一些想法可以帮助我...
    【解决方案2】:

    终于有办法了。

    我创建了一个虚拟活动并将上面提到的代码绑定到它。`

    <activity
        android:name=".controllers.activities.DummyActivity"
        android:launchMode="singleTask"
        android:theme="@style/AppTheme.NoActionBar">
    
    
        <intent-filter>
            <action android:name="com.mypackage.NOTIFICATION" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>
    

    如果我的应用在后台并且应用收到通知。单击通知时,它将打开虚拟活动,我在 onResume() 中调用 finish() 方法。因此,这个特定的活动甚至会在它打开之前完成,这将打开之前的活动,我正在检查是否已启动,如果它是错误的,我将重新启动应用程序。

    这不是一个直接的解决方案,但现在可以解决。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-01-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-29
      • 1970-01-01
      相关资源
      最近更新 更多