Bender Bender - 1 month ago 10
Android Question

IBM Mobilefirst : App gets restarted when I click on the Notification

I am developing android native app with MFP Integrated.
I have Implemented MFP push notification and it works fine. I get the notification. But when I click the notification my app restarts.

The actual issue was I have a splash activity which is launched on my app launch and where I am initializing all my MFP stuff and killing this activity taking the app to login activity.

And in My manifest file I am defining my receiver as below.

<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>


The receiver is defined in my splash activity but I am finishing this activity and going to login activity and then from login to other activities . Now splash activity is only called once in every app launch.

For this reason When I click on notification it is killing the other activities and launching splash activity again because it is asked to receive only in splash activity.

So can some body tell me how do I design my app so that I can receive the notification when I am on any activity of the app(It should not launch the splash activity but instead it should be on the same activity the app is open, and call the onrecieve message method)..

Please suggest.

I have asked a similar type of question before but could find the problem then, so I am posting this question with actual problem asking for solution.
Mobilefirst PushNotification: On click of the notification app is getting relaunched and onReceive method is not getting called

Answer

Finally i got some solution.

I have created a dummy activity and binding the above mention code to it.`

<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>

If my app is in background and app gets a notification . On clicking of Notification it will open the dummyactivity and i am calling finish() method in the onResume(). So this particular activity will be finished even before it is opened which will open the pervious activity and I am putting a check saying applaunched if it is false, I am relaunching the app.

This cant be a straight solution but it is a work around for now.

Comments