在应用程序中,我获取 CommosWare 的 WakefulIntentservice 方法。从 doWakefulWork 方法中我调用几个自定义的方法。例如:
@Override
protected void doWakefulWork(Intent arg0) {
exampleMethod();
}
private void exampleMethod() {
//Stuff
}
使我的程序更加清晰了,但是当我调用自定义的方法时,是否能丢失 WakeLock ?
只要没在这个方法里开子线程就不会。本身 IntentService 包括 WakefulIntentService 都是运行在独立的线程里的,WakefulIntentService 实现的机制简单来说就是在 IntentService 的 onHandleIntent() 里先获得 WakeLock 唤醒机器再调用 doWakefulWork() 完了再释放 WakeLock