当应用在后台运行时,一切正常,但是当我终止该应用时,BroadcastReceiver也仅在Android Oreo上被终止
protected Void doInBackground(Void... params) {
startTimer();
return null;
}
}
private void startTimer(){
timer = new Timer();
timerTask = new TimerTask() {
public void run() {
handler.post(new Runnable() {
public void run(){
// Toast.makeText(getApplicationContext()," iside startTimer startTimer ",Toast.LENGTH_LONG).show();
IntentFilter filter = new IntentFilter();
filter.addAction("android.provider.Telephony.SMS_RECEIVED");
filter.addAction(android.telephony.TelephonyManager.ACTION_PHONE_STATE_CHANGED);
registerReceiver(receiver, filter);
}
});
}
};
timer.schedule(timerTask, 1000, 1000);
}