1
我的AsyncTask
类运行良好,如果我的应用程序在后台,但如果我接听电话,它将停止运行。只要我挂断电话,我就会再次看到它的活动。它在我的应用和我的数据库之间进行通信我怎样才能让这个后台进程始终运行?android AsyncTask被电话拦截?
我的AsyncTask
类运行良好,如果我的应用程序在后台,但如果我接听电话,它将停止运行。只要我挂断电话,我就会再次看到它的活动。它在我的应用和我的数据库之间进行通信我怎样才能让这个后台进程始终运行?android AsyncTask被电话拦截?
尝试使用此
PhoneStateListener phoneStateListener = new PhoneStateListener() {
@Override
public void onCallStateChanged(int state, String incomingNumber) {
if (state == TelephonyManager.CALL_STATE_RINGING) {
// do your stuff here
} else if (state == TelephonyManager.CALL_STATE_IDLE) {
// do your stuff here
} else if (state == TelephonyManager.CALL_STATE_OFFHOOK) {
// A call is dialing, active or on hold
// do your stuff here
}
super.onCallStateChanged(state, incomingNumber);
}
};
TelephonyManager mgr = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
if (mgr != null) {
mgr.listen(phoneStateListener, PhoneStateListener.LISTEN_CALL_STATE);
}
的Asynctask类不intented将始终在后台运行,而不是你应该使用Services。 另外,您不必一直与您的数据库进行实时通信,您可以使用Content Provider。
希望这对你有所帮助。