我有一個intentservice可以被用戶和我的應用程序自動調用。我需要能夠在用戶註銷應用程序時終止所有待處理的意圖,但似乎無法使其工作。我嘗試過stopService()和stopself(),但意圖在用戶註銷後繼續觸發intentservice。我會嘗試獲取intent的id,但這很困難,因爲每次intentservice開始時,持有intent id的變量都是空的。這裏是我的intentservice代碼:我該如何取消所有待處理意圖的服務
public class MainUploadIntentService extends IntentService {
private final String TAG = "MAINUPLOADINTSER";
private GMLHandsetApplication app = null;
private SimpleDateFormat sdf = null;
public boolean recStops = true;
public MainUploadIntentService() {
super("Main Upload Intent Service");
GMLHandsetApplication.writeToLogs(TAG,
"GMLMainUploadIntentService Constructor");
}
@Override
protected void onHandleIntent(Intent intent) {
GMLHandsetApplication.writeToLogs(TAG, "onHandleIntent Started");
if (app == null) {
app = (GMLHandsetApplication) getApplication();
}
uploadData(app);
GMLHandsetApplication.writeToLogs(TAG, "onHandleIntent Finished");
}
@Override
public void onDestroy() {
GMLHandsetApplication.writeToLogs(TAG, "onDestroy Started");
app = null;
stopSelf();
GMLHandsetApplication.writeToLogs(TAG, "onDestroy completed");
}
public void uploadData(GMLHandsetApplication appl) {
//All of my code that needs to be ran
}
看來,實際意圖闕並IntentService是不提供給Android開發者。 – user638049