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 using wl_anonymousUserRealm at server, app is not calling onReceive method on clicking notification
Finally i got some solution.
I have created a dummy activity and binding the above mention code to it.`
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.
Setting up a GCM client in Android and Receiving downstream messages are great references you'll be looking into for your scenario.
You'll have to define the GCM Receivers and Services that are needed to receive the messages. This will greatly help for you to receive messages in any
Activity
(since aService
doesn't need any UI, andBroadcastReceiver
will help that the CPU is awake so the listener service will complete its task).Hope this helps!