繁体   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