GCM服务缺失,清除缓存 [英] GCM service is deleted with cache clearing

查看:217
本文介绍了GCM服务缺失,清除缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我与谷歌云消息传递的一个问题:

I have a problem with Google Cloud Messaging:

这是我使用的测试智能手机没有一个大的RAM,有时它还会删除我的应用程序的GCM服务,应该接收的消息。有时候,我的GCM服务的工作以及仅在1或2个小时,然后自动关闭(RAM时被强制清零)。

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

但我的应用程序的requierement是接收始终GCM的消息,或者至少有一个机会,有较长的时段(10-12小时)。我可以设置在我的应用程序或智能手机有一个relieable GCM服务?

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?

智能手机并没有看到我的应用程序的任何服务。下面是截图,您可以比较我与watsapp的应用程序:

The smartphone doesn't see any services in my app. Here is a screenshot where you can compare my app with watsapp:

我的应用程序与watsapp

我的smarphone使用MIUI的进程管理器。

My smarphone uses MIUI process manager.

下面是我对GCM清单的一部分:

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>

感谢您在您的帮助

推荐答案

如果您的应用程序停止了几个小时后收到短信,我怀疑问题是不是由那里是 GcmListenerService 。当收到客户端的GCM消息,该消息被传递到 GcmReceiver 在你的应用程序的清单中声明的​​实例。 GcmReceiver WakefulBroadcastReceiver GcmReceiver 然后将消息传递给 GcmListenerService 的你已经在你的应用程序中实现的子类。我猜测的 GcmReceiver 使用邮件传递 startService(),如果一个人做,这将创建该服务的一个实例不存在。如果系统破坏,因为内存pressure的服务,它会在收到新邮件时重新创建。

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 of GcmReceiver declared in your app's manifest. GcmReceiver is a WakefulBroadcastReceiver. GcmReceiver then delivers the message to the subclass of GcmListenerService you have implemented in your app. I am guessing the GcmReceiver delivers the message using startService(), 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.

这篇关于GCM服务缺失,清除缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆