How to handle this kind of exception? Given work is not active exception in Oreo while i m using unique job id across the app.

java.lang.RuntimeException: An error occurred while executing doInBackground()  
        at android.os.AsyncTask$3.done(AsyncTask.java:353)
        at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:383)
        at java.util.concurrent.FutureTask.setException(FutureTask.java:252)
        at java.util.concurrent.FutureTask.run(FutureTask.java:271)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
        at java.lang.Thread.run(Thread.java:764)
Caused by: java.lang.IllegalArgumentException: Given work is not active: JobWorkItem{id=2 intent=Intent { cmp=com.virinchi.mychat/com.virinchi.receiver.AnalysticsSubmit } dcount=1}
        at android.app.job.JobParameters.completeWork(JobParameters.java:221)
        at android.support.v4.app.JobIntentService$JobServiceEngineImpl$WrapperWorkItem.complete(JobIntentService.java:267)
        at android.support.v4.app.JobIntentService$CommandProcessor.doInBackground(JobIntentService.java:393)
        at android.support.v4.app.JobIntentService$CommandProcessor.doInBackground(JobIntentService.java:382)
        at android.os.AsyncTask$2.call(AsyncTask.java:333)
        at java.util.concurrent.FutureTask.run(FutureTask)

public class AnalysticsSubmit extends JobIntentService {
    private static String TAG = "AnalysticsSubmit";


    /**
     * Unique job ID for this service.
     */

    /**
     * Convenience method for enqueuing work in to this service.
     */


    public static void enqueueWork(Context context, Intent work) {
        try{
            enqueueWork(context, AnalysticsSubmit.class, JOB_ID, work);
        }catch (Exception ex){
            Log.e(TAG, "enqueueWork: ex"+ex.getMessage() );
        }

    }

    @Override
    protected void onHandleWork(Intent intent) {

        try {

            UtilsUserInfo userInfo = new UtilsUserInfo(DocApplication.getContext());
            int width = 0;
            int height = 0;
            String widthstr = "0";
            String heightstr = "0";

            JSONObject records = new JSONObject();
            JSONObject device_info = new JSONObject();

            WindowManager wm = (WindowManager) DocApplication.getContext().getSystemService(Context.WINDOW_SERVICE);

            DisplayMetrics displayMetrics = new DisplayMetrics();
            wm.getDefaultDisplay().getMetrics(displayMetrics);
            width = displayMetrics.widthPixels;
            height = displayMetrics.heightPixels;
            widthstr = String.valueOf(width);
            heightstr = String.valueOf(height);


            String device_model = Build.MODEL + " " + Build.VERSION.RELEASE;

            device_info.put("app_version", userInfo.getFromPreferences("version"));
            device_info.put("operating_system", getOsName());
            device_info.put("device_resolution", widthstr + "*" + heightstr);
            device_info.put("device_model", device_model);
            device_info.put("device_manufacturer", Build.MANUFACTURER);
            device_info.put("app_identifier", ResourceUtils.getResourceString(this, R.string.app_identifier_analytics));


            JSONArray event = new JSONArray();

            try {

                Realm realm = SingleInstace.getInstace().getRealm();

                realm.executeTransaction(new Realm.Transaction() {
                    @Override
                    public void execute(Realm realm) {
                        try {
                            JSONObject eventobj = null;
                            RealmResults<DocquityLog> results = realm.where(DocquityLog.class).findAll();
                            results.load();
                            for (DocquityLog obj : results) {

                                JSONObject session_time = new JSONObject();
                                JSONObject location = new JSONObject();
                                eventobj = new JSONObject();
                                eventobj.put("event_name", obj.getEvent_name());
                                eventobj.put("product_type", obj.getProduct_type());
                                eventobj.put("product_type_id", obj.getProduct_type_id());
                                eventobj.put("session_id", obj.getSession_id());
                                eventobj.put("local_id", obj.getId());
                                eventobj.put("screen_name", obj.getScreen_name());

                                if (!Validation.isEmptyString(userInfo.getFromPreferences("user_id"))) {
                                    eventobj.put("user_id", Integer.parseInt(userInfo.getFromPreferences("user_id")));

                                    if (userInfo.isKeyExist("untrack_user_identifier")) {
                                        eventobj.put("untrack_user_identifier", userInfo.getFromPreferences("untrack_user_identifier"));
                                        userInfo.removeKey("untrack_user_identifier");
                                    }

                                } else {
                                    eventobj.put("user_id", 0);
                                    eventobj.put("untrack_user_identifier", userInfo.getFromPreferences("untrack_user_identifier"));
                                }
                                session_time.put("start_time", obj.getStart_time());
                                session_time.put("end_time", obj.getEnd_time());
                                eventobj.put("session_time", session_time);
                                location.put("latitude", obj.getLatitude());
                                location.put("longitude", obj.getLongitude());
                                location.put("local", obj.getLocal());
                                location.put("time_zone", obj.getTime_zone());
                                eventobj.put("location", location);
                                event.put(eventobj);

                            }

                        } catch (Exception ex) {
                            LogEx.logExecption(TAG, "", ex);
                        }
                    }
                });


            } catch (Exception ex) {
                LogEx.logExecption(TAG, "", ex);
            } finally {
                SingleInstace.getInstace().destroyRealm();

            }


            records.put("device_info", device_info);
            records.put("event", event);


            // Log.e(TAG, " records "+records.toString());

            if (records != null && event.length() > 0) {

                //apiAnalysticWork(records.toString());
                ApiManager.getClientBasicAuthNewReactive(userInfo.getFromPreferences("user_auth_key"),
                        userInfo.getFromPreferences(userInfo.token_id),
                        ApiManager.GENRIC_API_VERSION_2, userInfo.getFromPreferences("version"),
                        GlobalSetting.Lng, "", ApiManager.DeviceType).getAnalysticRecord(records.toString())
                        .observeOn(AndroidSchedulers.mainThread())
                        .subscribeOn(Schedulers.computation())
                        .subscribe(searchResponse -> {
                            try {
                                int status = searchResponse.getStatus();
                                if (status == 1) {
                                    //     Log.e(TAG, "showSearchResult: success");
                                    // delete work

                                    try {

                                        Realm realm = SingleInstace.getInstace().getRealm();
                                        realm.executeTransaction(new Realm.Transaction() {
                                            @Override
                                            public void execute(Realm realm) {

                                                try {
                                                    RealmQuery q = realm.where(DocquityLog.class);
                                                    int x = 0;
                                                    for (Integer id : searchResponse.getAnalysticData().getSuccess_session_ids()) {

                                                        if (x != 0) {
                                                            q.or();
                                                        }
                                                        q = q.equalTo("id", id);

                                                        x++;
                                                    }
                                                    RealmResults<DocquityLog> filteredArticles = q.findAll();
                                                    filteredArticles.deleteAllFromRealm();

                                                } catch (Exception ex) {
                                                    Log.e(TAG, " ex " + ex.getMessage());
                                                    Crashlytics.logException(ex);
                                                }

                                            }
                                        });

                                    } finally {

                                        SingleInstace.getInstace().destroyRealm();
                                    }
                                    //RealmController.commitInput();

                                }
                            } catch (Exception ex) {
                                LogEx.logExecption(TAG, "", ex);
                            }


                        }, throwable -> LogEx.displayRetrofitError(TAG, throwable));

                // Log.e(TAG, "jsonWorkAnalystic:reords "+records.toString() );
            }

        } catch (JSONException e) {
            LogEx.logExecption(TAG, "JSONException", e);
        } catch (Exception e) {
            LogEx.logExecption(TAG, "OtherException", e);
        }

    }


    /*public AnalysticsSubmit() {
        super("AnalysticsSubmit");
    }

    @Override
    public void onDestroy() {
  //      Toast.makeText(this, "service done", Toast.LENGTH_SHORT).show();

    }

    @Override
    protected void onHandleWork(@NonNull Intent intent) {

    }
*/


    public String getOsName() {
        StringBuilder builder = new StringBuilder();
        // builder.append("android : ").append(Build.VERSION.RELEASE);

        Field[] fields = Build.VERSION_CODES.class.getFields();
        for (Field field : fields) {
            String fieldName = field.getName();
            int fieldValue = -1;

            try {
                fieldValue = field.getInt(new Object());
            } catch (IllegalArgumentException e) {
                e.printStackTrace();
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            } catch (NullPointerException e) {
                e.printStackTrace();
            }

            if (fieldValue == Build.VERSION.SDK_INT) {
                builder.append(fieldName);
            }
        }
        return builder.toString();
    }


}
0

There are 0 answers