Search code examples
android-asynctaskandroid-gradle-pluginbuild-errorasync-onprogressupdate

android AsyncTask::onProgressUpdate() gradle build error when I try to use anything from within the activity (UI thread)


I'm a little stumped. Before I start I should mention I use AndroidSutdio 2.3.3 (latest version at the time of writing).

What I'm trying to do

I have a basic activity what creates an AsyncTask and executes it. In the AsyncTask I want to update the UI after gathering some data. From what I've read, I should be able to call updateProgress() from within the doInBackground() method of the AsyncTask. This in turn should call the onProgressUpdate() method of the AsyncTask, inside of which I should be able to access data and methods from within the main activity.

The problem is

The problem is that the gradle builder complains about the methods used inside of onProgressUpdate(), the ones belonging to the main activity, are not declared. It is trying to find those methods and data inside the current AsyncTask instead of the activity.

In conclusion

  • I don't know if this works or not because I haven't been able to get past the build process to test it out.
  • Am I mixing up the UI thread with the activity, or are they the same exact thing?
  • I read that the onPreExecute, onPostExecute and onProgressUpdate of the AsyncTask are run on the UI thread. If this is correct, why am I getting the build errors?
  • Is there some sort of setting I need to corret in the AndroidStudio to overcome this?

Solution

  • Well, I found the problem. I didn't work because wrote the async task into a separate file. Declaring in within the activity class file solved the problem.