0
我從WakefullBroadcastReceiver當設備處於睡眠IntentService是沒有得到所謂的
Intent i = new Intent(context, MyService.class);
i.putExtras(bundle);
Log.i("StartService","Before Wakelock");
WakeLock lock = MyService.getLock(context);
Log.i("StartService","After Wakelock");
lock.acquire();
Log.i("StartService","After Aquire");
context.startService(i);
lock.release();
Log.i("StartService","After Release");
越來越顯示上述所有日誌觸發的IntentService。但我的服務沒有被調用。
IntentService
public class MyService extends IntentService {
private static final String NAME = MyService.class.getName() + ".Lock";
private static volatile WakeLock lockStatic = null;
synchronized public static PowerManager.WakeLock getLock(Context context) {
if (lockStatic == null) {
PowerManager mgr = (PowerManager) context
.getSystemService(Context.POWER_SERVICE);
lockStatic = mgr.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, NAME);
lockStatic.setReferenceCounted(true);
}
return (lockStatic);
}
public MyService(String name) {
super(name);
}
public MyService() {
super("MyService");
}
@Override
protected void onHandleIntent(Intent intent) {
try {
Log.i("IntentService", "In HandleIntent");
} finally {
}
}
}
誰能幫助我?
你有沒有在清單文件中聲明你的服務? – Kartheek
如果您實際使用的是'WakefulBroadcastReceiver',並且您按照文檔使用它,則不需要您自己的'WakeLock'。 – CommonsWare
@Kartheek是的,而當設備是活動服務被稱爲 – user3616287