简体   繁体   English

终止服务后,Android GCM无法接收通知

[英]Android GCM not receiving notification when Service has been killed

I know there is a lot of questions about this, but every time the issue where because they were "force-killing" their app through the App Manager. 我知道有很多问题,但是每次出现问题时,都是因为他们通过应用管理器“强行杀死”他们的应用。

This isn't my case. 这不是我的情况。

I run a service, that should handle the GCM Notification. 我运行了一项服务,该服务应处理GCM通知。 When the service is running, everything works just fine ! 服务运行时,一切正常!

BUT

If I launch another App really eager of RAM, let's say Something like a game, the Android will kill my service (in order to restart it later when RAM is no more an issue). 如果我启动另一个真正渴望RAM的应用程序,则可以说Android之类的游戏会终止我的服务(以便在RAM不再成为问题时稍后重新启动它)。

The thing is, If I start the said game, and send while the game is running (when I'm sure that the service has been killed by the device -- looking at running processes on Eclipse), it does not get any messages... Until I stop the game, wait like 3-4 minutes (probably for the GC to come around) then, and only then (when the service is restarted) I get the GCM Notifications. 问题是,如果我启动上述游戏,然后在游戏运行时发送(当我确定该服务已被设备杀死-查看Eclipse上正在运行的进程),它将不会收到任何消息。 ..在我停止游戏之前,请等待3-4分钟(可能是GC出现),然后才等待(当服务重新启动时)我会收到GCM通知。

The entry point of the application makes me think that the service is restarted because RAM usage was low enough to start my service back, and not because GCM received a notification. 应用程序的入口点使我认为服务已重新启动是因为RAM使用率足够低,无法重新启动我的服务,而不是因为GCM收到了通知。

Is that a normal behavior of GCM notification system ? 这是GCM通知系统的正常行为吗? Is their any way to get the service run as soon as I get a GCM notification ? 我收到GCM通知后,他们有什么办法可以使服务开始运行?

Here's what's in the manifest : 这是清单中的内容:

<receiver
        android:name="com.my.package.service.C2DMMessageReceiver"
        android:permission="com.google.android.c2dm.permission.SEND">
    <intent-filter>
        <action android:name="com.google.android.c2dm.intent.RECEIVE"/>
        <action android:name="com.google.android.c2dm.intent.REGISTRATION"/>

        <category android:name="com.my.package.service"/>
    </intent-filter>
</receiver>

And Here's the entire class C2DMMessageReceiver : 这是整个类C2DMMessageReceiver:

public class C2DMMessageReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();
        if ("com.google.android.c2dm.intent.RECEIVE".equals(action)) {
            Log.d("C2DM", "#### GOT PUSH ####");
            Communication2.getInstance().reconnect();
        }
    }
}

This is by default by design. 这是默认情况下的设计。 Starting from android 3.1 and above any application user removed from the tasks or application manager wont receive any intents broadcasted , based on the following conditions.... 从android 3.1开始,基于以下条件,从任务或应用程序管理器中删除的任何应用程序用户将不会收到任何广播的意图。

https://developer.android.com/about/versions/android-3.1.html#launchcontrols https://developer.android.com/about/versions/android-3.1.html#launchcontrols

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM