I am working with JobIntentService
class that does some background work:
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");
}
}
and this is how work is enqueued for this class:
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);
This works perfectly on my Samsung Android 9. In the logs I see this for every job:
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
but when I test this out on Xiaomi Android 7, I see that this onHandleWork
method is called indefinitely:
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
...
why is that? How do I stop this?