-1

On old code I am using AsyncTask to perform operation.Now AsyncTask is depreciated what to use instead of this.

 new MyAsyncTask(context, true, new MyAsyncTask.AsynTaskListener() {

            public ResultPojo resultPojo = null;

            @Override
            public void doInBackgroundOpration(SyncServer syncServer) {

                resultPojo = syncServer.saveCleaningCompleant(cleaningCompleantPojo);
                Log.d("error"," "+new Gson().toJson(resultPojo));
            }

            @Override
            public void onFinished() {

                if (!AUtils.isNull(resultPojo)) {

                    Log.d("error"," "+new Gson().toJson(resultPojo));

                    if (resultPojo.getStatus().equals(AUtils.STATUS_SUCCESS)) {

                        AUtils.success(context, "" + context.getString(R.string.submit_done), Toast.LENGTH_SHORT);
                        AUtils.deleteAllImagesInTheFolder();
                        CleaningComplaintActivity.this.finish();
                    } else {
                        AUtils.error(context, "" + context.getString(R.string.submit_error), Toast.LENGTH_SHORT);
                    }
                } else {
                    AUtils.error(context, "" + context.getString(R.string.serverError), Toast.LENGTH_SHORT);
                }

            }
        }).execute();

    

Error showing on .execute what should i do for it

a_local_nobody
  • 7,947
  • 5
  • 29
  • 51
gopssays
  • 41
  • 7
  • 1
    Does this answer your question? [Android AsyncTask API deprecating in Android 11.What are the alternatives?](https://stackoverflow.com/questions/58767733/android-asynctask-api-deprecating-in-android-11-what-are-the-alternatives) – a_local_nobody Oct 06 '21 at 11:44
  • @a_local_nobody- there is error on .execute how to solve this without changing code – gopssays Oct 06 '21 at 11:48

1 Answers1

0

If you are using java then you can go with RxJava. if you are using kotlin the you can use coroutine to achive asynctask functionality in android

here is simple coroutine example: Coroutine example