What if you use a wakelock. For example:
@Override
public void onCreate(Bundle savedInstanceState) {
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "My Tag");
wl.acquire();
// do your things, even when screen is off
}
@Override
protected void onDestroy() {
wl.release();
}
You must also have a wakelock permission is AndroidManifest.xml
uses-permission android:name="android.permission.WAKE_LOCK"
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…