1

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 class to free memory? If yes, how to prevent this?

alexanderblom
  • 8,632
  • 6
  • 34
  • 40
Geltrude
  • 1,093
  • 3
  • 17
  • 35

2 Answers2

3

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

Vladimir Ivanov
  • 42,730
  • 18
  • 77
  • 103
  • Note that you could still store data as static, as described in https://stackoverflow.com/questions/3162715/save-data-in-broadcast-receiver – domen Mar 18 '16 at 16:59
2

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.

alexanderblom
  • 8,632
  • 6
  • 34
  • 40