简体   繁体   English

调用Android IntentService onDestroy而不是onHandleIntent

[英]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. 检查了它的日志。onDestroy()方法被调用,而不是onHandleIntent()被调用我正在使用两个Intent服务,并且为这两个都编写了类似的代码...但是一个一直运行,但第二个IntentService一直运行...有时它会运行,有时它会在整个项目中进行任何更改。 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. 代码中的task.execute()方法中包含一个if循环,并且条件为false。 so there wasn't anything for the IntentService to do..therefore it was destroying itself. 因此,IntentService没什么可做的。因此它正在破坏自身。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 没有调用IntentService OnHandleIntent - IntentService OnHandleIntent is not being called 使用IntentService进行位置监听,但onHandleIntent后立即调用onDestroy - Using IntentService for Location listening but onDestroy called immediately after onHandleIntent 在onHandleIntent之后立即调用IntentService的onDestroy方法 - IntentService's onDestroy method getting called straight after onHandleIntent IntentService onCreate()调用但onHandleIntent()没有 - IntentService onCreate() called but onHandleIntent() not OnHandleIntent()没有在IntentService中调用 - OnHandleIntent() not called in IntentService 在onDestroy()触发后,IntentService onHandleIntent()仍在运行 - IntentService onHandleIntent() still running after onDestroy() fired Android:onDestroy()中使用的IntentService - Android: IntentService used in onDestroy() intentService :为什么我的 onHandleIntent 从未被调用? - intentService : why my onHandleIntent is never called? 使用bindService启动IntentService时是否应该调用onHandleIntent? - Should onHandleIntent be called when IntentService is started with bindService? 启动IntentService会引发NullpointerException,并且永远不会调用onHandleIntent() - Starting IntentService throws NullpointerException and onHandleIntent() is never called
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM