0

I'm working on an Android App using Java Language. I get into a weird problem. I'm using a third-party library that requests to a the server, get some data, make some changes to the data and then gives it to me. So on my part, I'm not doing any networking-related work. I just call the function of the library and gets the data.

Now the problem is I want to wait until the function returns the data, then the code on the next line executes. But it returns the data when the activity finishes.

I check the source code of the library on github it build around an AsyncTask and do the work in Background Thread. As I cannot change the code of the library so I want when I call the function, it waits until it finishes its work then it moves to the next line of the code to execute.

So please help me if anybody have idea how to do it.

  • Please, add your code call the AsyncTask function – Tungken Jan 08 '21 at 04:20
  • 1
    call the library method in doInBackground() method of AsyncTask and then pass the result of that method to onPostExecute(). And after getting the result do your next things in onPostExecute() – Bhargav Thanki Jan 08 '21 at 04:23

1 Answers1

1

You should see this post: AsyncTask Android example

You need to use the postExecute() method to launch your custom method to continue the flow.

BTW AsyncTask is near to be deprecated, so maybe you need to use something like this post: Android AsyncTask API deprecating in Android 11.What are the alternatives? or maybe learn Kotlin and use coroutines.

Capps99
  • 111
  • 1
  • 3