forked from thunderbird/thunderbird-android
/
ShutdownReceiver.java
39 lines (33 loc) · 1.33 KB
/
ShutdownReceiver.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package com.fsck.k9.service;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import timber.log.Timber;
/**
* Capture the system shutdown event in order to properly free resources.
*
* <p>
* It is advised not to statically register (from AndroidManifest.xml) this
* receiver in order to avoid unnecessary K-9 launch (which would defeat the
* purpose of that receiver). Using AndroidManifest.xml instructs Android to
* launch K-9 if not running, defeating the purpose of this receiver. <br>
* The recommended way is to register this receiver using
* {@link Context#registerReceiver(BroadcastReceiver, android.content.IntentFilter)}
* </p>
*/
public class ShutdownReceiver extends BroadcastReceiver {
@Override
public void onReceive(final Context context, final Intent intent) {
if (Intent.ACTION_SHUTDOWN.equals(intent.getAction())) {
Timber.i("System is shutting down, releasing resources");
// prevent any scheduled intent from waking up K-9
BootReceiver.purgeSchedule(context);
/*
* TODO invoke proper shutdown methods (stop any running thread)
*
* 20101111: this can't be done now as we don't have proper
* startup/shutdown sequences
*/
}
}
}