0
wakelocks를 올바르게 구현하지 않아야합니다. 이게 내가 한 일이야. 이 올바른지?Wakelocks가있는 상태에서도 Android 서비스가 중지됨
private static final String LOCK_NAME_STATIC="domination.shredAssistant.locationService";
private static volatile PowerManager.WakeLock lockStatic=null;
synchronized private static PowerManager.WakeLock getLock(Context context) {
if (lockStatic==null) {
PowerManager mgr=(PowerManager)context.getSystemService(Context.POWER_SERVICE);
lockStatic=mgr.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
LOCK_NAME_STATIC);
lockStatic.setReferenceCounted(true);
}
return(lockStatic);
}
및
//onStart
public void onStart(Intent intent, int startId) {
super.onStart(intent, startId);
if (running == false) {
Context ctxt=getApplicationContext();
getLock(ctxt).acquire();
running = true;
readResorts();
serviceHandler = new Handler();
serviceHandler.postDelayed(new RunTask(),1000L);
runtest=true;
locupdate(0,0);
}
}
나는 서비스가 여전히 내가 사용하더라도 일정 기간 getLock (ctxt) .acquire 후 살해 이유) (알아낼 수없는 ONSTART 방법; 당신의 도움을 주셔서 감사합니다! -Dom