当应用程序在Oreo设备上被杀死时,如何在JobService后台运行BroadcastReceiver?

时间:2018-10-28 09:39:56

标签: java android kotlin android-8.0-oreo

当应用在后台运行时,一切正常,但是当我终止该应用时,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);
}

0 个答案:

没有答案