2
在while(true)語句中,我創建了一個將在onHandleIntent中運行一個case的意圖。但是,我無法使用startService(i)啓動意圖,而無需將活動類擴展到我的LocationTracker類。當我做LocationTracker擴展Activity時,我可以使用startService(i),但應用程序中斷並停止工作。我收到錯誤「活動已泄漏服務連接」。無論如何要解決這個問題嗎?我需要的方法在BackgroundService類中是私有的,我的MainScreen擴展活動使用相同的代碼片段來啓動服務。是否我同時運行兩個意圖,如果有的話,我可以在另一個類中調用私有方法嗎?如何實現startService(i)不在MainActivity上
public class LocationTracker{
DSApi dsApi=new DSApi((ContextWrapper)mContext,null);
if(dsApi.initialize(AppSettings.IP_ADDRESS,AppSettings.PORT,false)) {
interv = (int)dsApi.sendLocationInfo(l);
if (dsApi.needRemoteWipe()) {
while(true){
Intent i = IntentFactory.getBackgroundService();
i.putExtra(BackgroundService.EXTRA_OPERATION,BackgroundService.OPERATION_BACKUP);
startService(i);
AppSettings.addEventLog(EventLog.TYPE_BACKUP, "Data backed up");
break;
}
AppSettings.setRemoteWipe(true);
}
}
Log.d("SendLocationTask", "finished");}