简体   繁体   中英

Android IntentService onDestroy being called instead of onHandleIntent

Checked the log for it.. onDestroy() method gets called instead of onHandleIntent() i am using two intent services, and have written similar code for both... but one runs all the time but for the second intentService(code attached)...sometimes it runs and sometimes it doesn't without changing anything in the whole project. can anyone please help?

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);
    }
}

the task.execute() method in code had a if loop in it and the condition was false. so there wasn't anything for the IntentService to do..therefore it was destroying itself.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM