Android的广播接收器应用程序后从正在运行的应用列表关闭不会被调用 [英] Android BroadcastReceiver Not being called after app closed from Running App List

本文介绍了Android的广播接收器应用程序后从正在运行的应用列表关闭不会被调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在试图实施通知中的Andr​​oid应用程序,我看到了通知,如果用户关闭从正在运行的应用程序列表中的应用程序(顶部向下滑动,然后横向轻扫不再工作 - 而不是强制退出其正常将关闭所有未来的调用按照谷歌的规格)。使用后退按钮有时会导致相同的行为,但并非总是如此。

我从一切的理解是,我研究的是,只有一种力量停止用户应该被调用停止广播接收器。

下面是相关code和设置从Android清单,注意,当应用程序是开放的或通过home键左都工作正常。

Android清单相关章节:

 <使用许可权的android:NAME =com.google.android.c2dm.permission.RECEIVE/>
<使用许可权的android:NAME =android.permission.WAKE_LOCK/>    <接收
        机器人:名字=mypackage.android.gcm.GCMBroadcastReceiver
        机器人:权限=com.google.android.c2dm.permission.SEND
        机器人:出口=真正的>
        &所述;意图滤光器>
            <作用机器人:名字=com.google.android.c2dm.intent.RECEIVE/>
            <类机器人:名字=mypackage.android/>
        &所述; /意图滤光器>
        &所述;意图滤光器>
            <作用机器人:名字=com.google.android.c2dm.intent.REGISTRATION/>
            <类机器人:名字=mypackage.android/>
        &所述; /意图滤光器>
    < /接收器>
    <服务
        机器人:名字=mypackage.gcm.GCMIntentService
        机器人:stopWithTask =假
        机器人:出口=假>
    < /服务>

下面是我的类中的覆盖 WakefulBroadcastReceiver

 公共类GCMBroadcastReceiver扩展WakefulBroadcastReceiver {@覆盖
公共无效的onReceive(最终上下文的背景下,最终的意图意图){
    尝试{
        //明确指定GcmIntentService将处理这个意图。
        组件名排版=新单元名(context.getPackageName(),GCMIntentService.class.getName());
        //启动该服务,保持清醒的设备,而它正在启动。
        startWakefulService(上下文,(intent.setComponent(化合物)));
        的setResult code(Activity.RESULT_OK);
    }赶上(例外五){
        //记录它,继续前进
        Log.d(GCMBroadcastReceiver,的onReceive,E);
    }
}


解决方案

看起来你迷迷糊糊差不多的<一个href=\"http://stackoverflow.com/questions/31535891/gcm-push-notification-for-background-app-causes-crash/31862768\">issue我做了,我想用GCMReceiver和GCMListenerService没有为你工作过。
这个问题是报告的错误。希望在机票上的解决方法将帮助你。

In attempting to implement notifications in an android app, I am seeing that the notifications no longer work if a user closes the app from the Running App List (top swipe down and then horizontal swipe - not force quit which properly would shut down all future invocations as per google specs). Using the back button sometimes causes the same behaviour, though not always.

My understanding from everything that I have researched is that only a force stop by the user should stop the Broadcast Receiver from being invoked.

Here is the relevant code and settings from the Android Manifest, note that all works fine when the app is open or left via the home button.

Android Manifest Relevant Sections:

<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE"/>
<uses-permission android:name="android.permission.WAKE_LOCK" />

    <receiver
        android:name="mypackage.android.gcm.GCMBroadcastReceiver"
        android:permission="com.google.android.c2dm.permission.SEND"
        android:exported="true">
        <intent-filter>
            <action android:name="com.google.android.c2dm.intent.RECEIVE" />
            <category android:name="mypackage.android" />
        </intent-filter>
        <intent-filter>
            <action  android:name="com.google.android.c2dm.intent.REGISTRATION" />
            <category android:name="mypackage.android" />
        </intent-filter>
    </receiver>
    <service
        android:name="mypackage.gcm.GCMIntentService"
        android:stopWithTask="false"
        android:exported="false">
    </service>

Here is my class that overrides WakefulBroadcastReceiver:

public class GCMBroadcastReceiver extends WakefulBroadcastReceiver {

@Override
public void onReceive(final Context context, final Intent intent) {
    try {
        // Explicitly specify that GcmIntentService will handle the intent.
        ComponentName comp = new ComponentName(context.getPackageName(),  GCMIntentService.class.getName());
        // Start the service, keeping the device awake while it is launching.
        startWakefulService(context, (intent.setComponent(comp)));
        setResultCode(Activity.RESULT_OK);
    } catch(Exception e) {
        //Log it, and move on
        Log.d("GCMBroadcastReceiver", "onReceive", e);
    }
}

解决方案

It looks like you stumbled about the same issue I did and I guess using GCMReceiver and GCMListenerService didn't work for you too. This problem is a reported bug. Hopefully the workarounds in the ticket will help you.

这篇关于Android的广播接收器应用程序后从正在运行的应用列表关闭不会被调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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