1

JobIntentServiceはいくつかのバックグラウンド作業を行うクラスで作業しています:


public class JsInvokerJobService extends JobIntentService {
    /**
     * Unique job ID for this service.
     */
    static final int JOB_ID = 1000;
    private static final String CHANNEL_ID = "AppsAndJunk";
    private static final String TAG = "JsInvokerJobService";


    /**
     * Convenience method for enqueuing work in to this service.
     */
    static void enqueueWork(Context context, Intent work) {
        enqueueWork(context, JsInvokerJobService.class, JOB_ID, work);
    }

    private void createNotificationChannel() {
        ...
    }

    final Handler mHandler = new Handler();

    @Override
    protected void onHandleWork(final Intent intent) {
        createNotificationChannel();
        Log.i(TAG, "Executing work: " + intent);

        mHandler.post(new Runnable() {
            @Override public void run() {
                Log.i(TAG, "Inside runnable " + intent);
                JsInvokerJobService.this.startService(intent);
            }
        });

        Log.i(TAG, "Finished work: " + intent);
    }
    @Override
    public void onDestroy() {
        super.onDestroy();
        Log.i(TAG, "All work complete");
    }


}

これは、このクラスの作業がキューに入れられる方法です。

Intent serviceIntent = new Intent(context, JsInvokerService.class);
serviceIntent.putExtra("intentAction", intentAction);
serviceIntent.putExtra("intentData", intentData);
if(originalIntentExtras != null) {
    serviceIntent.putExtras(originalIntentExtras);
}
JsInvokerJobService.enqueueWork(context, serviceIntent);

これは、Samsung Android 9 で完全に動作します。ログでは、すべてのジョブについて次のように表示されます。

09-30 11:31:03.599 10650 10924 I JsInvokerJobService: Executing work: Intent { cmp=com.smartsecurityxzt/.JsInvokerJobService (has extras) }
09-30 11:31:03.599 10650 10924 I JsInvokerJobService: Finished work: Intent { cmp=com.smartsecurityxzt/.JsInvokerJobService (has extras) }
09-30 11:31:03.599 10650 10650 I JsInvokerJobService: Inside runnable Intent { cmp=com.smartsecurityxzt/.JsInvokerJobService (has extras) }
09-30 11:31:03.607 10650 10650 I JsInvokerJobService: All work complete

しかし、Xiaomi Android 7 でこれをテストすると、このonHandleWorkメソッドが無期限に呼び出されることがわかります。

09-30 11:31:03.599 10650 10924 I JsInvokerJobService: Executing work: Intent { cmp=com.smartsecurityxzt/.JsInvokerJobService (has extras) }
09-30 11:31:03.599 10650 10924 I JsInvokerJobService: Finished work: Intent { cmp=com.smartsecurityxzt/.JsInvokerJobService (has extras) }
09-30 11:31:03.599 10650 10650 I JsInvokerJobService: Inside runnable Intent { cmp=com.smartsecurityxzt/.JsInvokerJobService (has extras) }
09-30 11:31:03.607 10650 10650 I JsInvokerJobService: All work complete
09-30 11:31:03.610 10650 10700 I JsInvokerJobService: Executing work: Intent { cmp=com.smartsecurityxzt/.JsInvokerJobService (has extras) }
09-30 11:31:03.611 10650 10700 I JsInvokerJobService: Finished work: Intent { cmp=com.smartsecurityxzt/.JsInvokerJobService (has extras) }
09-30 11:31:03.611 10650 10650 I JsInvokerJobService: Inside runnable Intent { cmp=com.smartsecurityxzt/.JsInvokerJobService (has extras) }
09-30 11:31:03.619 10650 10650 I JsInvokerJobService: All work complete
09-30 11:31:03.623 10650 10784 I JsInvokerJobService: Executing work: Intent { cmp=com.smartsecurityxzt/.JsInvokerJobService (has extras) }
09-30 11:31:03.623 10650 10784 I JsInvokerJobService: Finished work: Intent { cmp=com.smartsecurityxzt/.JsInvokerJobService (has extras) }
09-30 11:31:03.623 10650 10650 I JsInvokerJobService: Inside runnable Intent { cmp=com.smartsecurityxzt/.JsInvokerJobService (has extras) }
09-30 11:31:03.630 10650 10650 I JsInvokerJobService: All work complete
09-30 11:31:03.633 10650 10703 I JsInvokerJobService: Executing work: Intent { cmp=com.smartsecurityxzt/.JsInvokerJobService (has extras) }
09-30 11:31:03.633 10650 10703 I JsInvokerJobService: Finished work: Intent { cmp=com.smartsecurityxzt/.JsInvokerJobService (has extras) }
09-30 11:31:03.634 10650 10650 I JsInvokerJobService: Inside runnable Intent { cmp=com.smartsecurityxzt/.JsInvokerJobService (has extras) }
09-30 11:31:03.639 10650 10650 I JsInvokerJobService: All work complete
...

何故ですか?どうすればこれを止めることができますか?

4

0 に答える 0