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


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.