开发者

Does BroadcastReceiver can be killed from Android OS to free memory?

My app look at arriveed email in K9 client in this way...

1) AndroidManifest:

    <receiver
        android:name="com.myapp.K9MailReceiver">
        <intent-filter>
            <action
                android:name="com.fsck.k9.intent.action.EMAIL_RECEIVED" />
            <data
                android:scheme="email" />
        </intent-filter>
    </receiver>

2) My Broadcast Receiver:

public class K9MailReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(final Context context, final Intent intent) {

        final Intent serviceIntent = new Intent(context, MyService.class);
        serviceIntent.putExtra(Prepare.MAIL, intent.getExtras());
        context.startService(serviceIntent);

    }
}

My question: is it possible that Android decides to kill my K9MailReceiver 开发者_Python百科class to free memory? If yes, how to prevent this?


Any BroadcastReceiver doesn't appear constantly in memory. It get's instantiated when the intent gets received , and killed after onReceive() method is finished.


A receiver only runs when it is being called, so no. Be sure to keep run time under 5 sec though.

However your service may be killed at any time. You can make sure to keep it running by posting an ongoing notification but you probably should not. If it is killed in a low memory situation it will be restarted later.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜