This function is giving me the following error:
@Override
protected Boolean doInBackground(Void... args0) {
updateJSONdata();
return null;
}
This function is giving me the following error:
@Override
protected Boolean doInBackground(Void... args0) {
updateJSONdata();
return null;
}
I believe that within updateJSONdata()
you are calling Toast
. This is not allowed because Toast
can only be called on the main thread, which is responsible for screen updates, whereas the doInBackground()
method executes on a secondary thread, which is not allowed to refresh the screen. >
This can also happen if you are instantiating a Handler
within updateJSONdata()
. Handler
is able to execute code on the main thread and therefore call Toast
. If this is the case, one way to correct the error would be to instantiate the Handler
passing Looper.getMainLooper()
, that is:
new Handler(Looper.getMainLooper())
But since you are using AsyncTask
, you should not instantiate Handler
, but instead execute statements on the main thread using the AsyncTask
API, ie overwriting and calling methods that AsyncTask
itself to refresh the screen during or after running doInBackground()
.
These methods are:
publishProgress()
or doInBackground()
after running publishProgress()
. Unlike the latter, which runs on a separate thread, these methods I've run run on the main thread (making use of a publishProgress()
internally) and are the appropriate methods for you to overwrite and refresh the screen.
I hope it's clear, any questions are just a comment.
Put the implementation of your updateJSONdata();
function to facilitate the help.
At first, inside threads that are not runOnUiThread you should not manipulate views of the main thread (Activity)