在棉花糖上正确停止JobService

时间:2019-04-18 11:50:52

标签: android firebase-job-dispatcher jobservice

在我的应用中,我使用JobService做一些工作。 我在true中返回onStartJob(),在某些情况下,我在onStopJob()中重新安排了时间。

我有一个名为stopService()的静态方法,在这里我叫context.stopService()

public static void stopService(Context context){

        Log.e(LOG_TAG, "stopService() --> calling for context.stopService()");
        if(isRunning(context)) {
            Log.e(LOG_TAG, "the service is running, performing stop.");
            context.stopService(new Intent(context, ScreenReceiverRegistrationJobService.class));
        }
        else{
            Log.e(LOG_TAG, "the service is not running doing nothing.");
        }
    }

现在,当我在Android Oreo / Pie上运行它时,我在日志记录中看到onStopJob()和服务的onDestroy()中的日志。

但是,当我尝试在Android M上运行它时,没有看到来自onStop()onDestroy()的任何日志。

我还应该指出,当我想停止服务时,我也会要求

FireBaseJobDispatcher.cancel("jobTag");

是什么导致了Android M而不是O / P上的这种行为?

0 个答案:

没有答案