當我的Activity退出時,我在警報中註冊了一個掛起的意圖,這將在60秒內啓動一個NotificationService。的onCreate()的代碼低於:服務被殺,而不是內存原因
PlayLogSender.getInstance(this).startSend();
和startSend():
public void startSend(){
new Thread(){
@Override
public void run(){
log("[thread]started");
int interval=20;
try{
//wait for QTRadioService starting in case of this is a APP launch
Thread.sleep(interval*1000);
}catch(Exception e){}
log("sleep "+s+"s done");
while(some condition){
......
}
}
}.run()
}
而當PlayLogSender的線程完成睡覺,機器人殺死NotificationService;然後重新啓動它並再次殺死它。最後NotificationService再也沒有起來。我試圖將「間隔」設置爲15,然後一切正常。所以我認爲這不是因爲android殺死它的內存。
任何人都可以幫忙嗎?爲什麼Android會殺死我的服務?
非常感謝! – Guocheng