I have a problem with Google Cloud Messaging:
The test smartphone that I use does not have a big RAM and sometimes it deletes also the GCM service of my app that should receive the messages. Sometimes my GCM service works well only during 1 or 2 hours and then is automatically switched off (when RAM is forcibly cleared).
But the requierement of my app is to receive GCM messages always or at least to have an opportunity to have longer sessions (10-12 hours). What can I set up in my app or smartphone to have a relieable GCM service?
The smartphone doesn't see any services in my app. Here is a screenshot where you can compare my app with watsapp:
My smarphone uses MIUI process manager.
Here is my Manifest part about GCM:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="my.app.path" >
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<!-- ... other permissions -->
<permission
android:name="my.app.path.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="my.app.path.permission.C2D_MESSAGE" />
<application
...>
<!-- ... activites... -->
<receiver
android:name="com.google.android.gms.gcm.GcmReceiver"
android:exported="true"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="my.app.path" />
</intent-filter>
</receiver>
<service
android:name=".MyGcmListener"
android:exported="false"
android:enabled="true" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
</intent-filter>
</service>
</application>
</manifest>
Thank you in advance for your help
If your app stops receiving messages after a few hours, I suspect the problem is not caused by there being no instance of
GcmListenerService
. When a GCM message is received by a client, the message is passed to the instance ofGcmReceiver
declared in your app's manifest.GcmReceiver
is aWakefulBroadcastReceiver
.GcmReceiver
then delivers the message to the subclass ofGcmListenerService
you have implemented in your app. I am guessing theGcmReceiver
delivers the message usingstartService()
, which will create an instance of the service if one does not exist. If the system destroys the service because of memory pressure, it will be recreated when a new message is received.