android接收器在干净的ram后停止

时间:2013-10-14 13:16:25

标签: android

我有一个gcm接收器,但在重新启动手机和清洁内存之前它无法正常工作。我应该改变什么以保证接收器始终有效?

   <activity
            android:name="com.example.diyet.MainActivity"
            android:label="@string/app_name"
            android:screenOrientation="portrait" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>

        </activity>

<activity android:name="com.plugin.gcm.PushHandlerActivity"/>
<receiver android:name="com.plugin.gcm.CordovaGCMBroadcastReceiver" 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.plugin.gcm" />
    </intent-filter>
</receiver>
<service android:name="com.plugin.gcm.GCMIntentService" />,

提前致谢

2 个答案:

答案 0 :(得分:0)

如果您想手动启动接收器,请使用

您活动中的

registerReceiver(receiver)

答案 1 :(得分:0)

抱歉,我对GCM一无所知,但如果我说得对,你就有以下可能性之一

如果您的GCMIntentService是自定义的,您可以使此服务STICKY因此操作系统在崩溃后重新启动它。为此,您必须在onStartCommand方法中返回return Service.START_STICKY;

此外,您可以注册android.intent.action.BOOT_COMPLETED以在设备启动后立即启动服务。

如果你想阻止服务崩溃,当应用程序崩溃时你必须把它放在另一个线程中。这可以通过在清单中设置自定义进程名称来实现

android:process="com.gigatronik.presenter.serialport.SerialPortListenerService"/

我将编辑此答案,如果您可以提供有关您的问题的更多信息,因为我从未使用过GCM