簡體   English   中英

調用Android IntentService onDestroy而不是onHandleIntent

[英]Android IntentService onDestroy being called instead of onHandleIntent

檢查了它的日志。onDestroy()方法被調用,而不是onHandleIntent()被調用我正在使用兩個Intent服務,並且為這兩個都編寫了類似的代碼...但是一個一直運行,但第二個IntentService一直運行...有時它會運行,有時它會在整個項目中進行任何更改。 誰能幫忙嗎?

public class GetDataService extends IntentService {
    private static final String TAG="GetDataService";

    public GetDataService(){
        super("GetDataService");
    }
    @Override
    protected void onHandleIntent(Intent intent) {
        GetDataTask task= new GetDataTask();
        Log.d(TAG,intent.getStringExtra(GetDataTask.INSTA_TOKEN_URL));
        task.execute(this,intent);
        ApplicaitonsData.GetDataServiceRunning=true;
        Log.d(TAG,"data service running status = "+ ApplicaitonsData.GetDataServiceRunning);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        ApplicaitonsData.GetDataServiceRunning=false;
        Log.d(TAG,"data service running status = "+ApplicaitonsData.GetDataServiceRunning);
    }
}

代碼中的task.execute()方法中包含一個if循環,並且條件為false。 因此,IntentService沒什么可做的。因此它正在破壞自身。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM