I don't see anything wrong with MyAsyncTask , but there are other things that can go wrong.
Running AsyncTask
From Android Docs
Threading Rules
There are several streaming rules that must be followed for this class to work properly:
- The AsyncTask class must be loaded into the user interface thread. This is done automatically with JELLY_BEAN.
- A task instance must be created in the user interface thread.
- execute (Params ...) must be called in the user interface thread.
- Do not call onPreExecute (), onPostExecute (Result), doInBackground (Params ...), onProgressUpdate (Progress ...) manually.
- A task can be executed only once (when trying to execute a second execution, an exception will be thrown).
You do not show where you usually create the instance, and you complete the task, so make sure you do this in code that is already in the UI / main interface. Please note that the first dot with a marker may explain why this works for you on some devices and not on others.
Creating a view hierarchy
Message informs you
Only the source stream that created the view hierarchy can touch its views.
and you assume that this is because your async task (oddly enough) is trying to change the user interface in the background thread. However, it is possible that you will get this error, since an asynchronous task changes the user interface in the main thread, but the user interface ( ProgressBar ) was not created correctly in the first place.
See this question for an example of how you can erroneously create an idea about the wrong thread (nothing but the main thread) and get the same error.
More details
However, I would like to see exactly where you register the stream identifier and what values ββyou get. If you check my first two sentences and they do not solve your problem, we may need additional information.
You also mention Handler (?), But donβt show how and where you use it. Usually using AsyncTask eliminates the need to use Handler , so I'm a little worried about how you can use this.
Update
In the discussion in the comments below, it seems that the problem here is the one discussed in this question . Some code probably works in the background thread, first causing the AsyncTask class to load. The initial implementation (pre-Jelly Bean) of AsyncTask required loading the class into the main thread (as indicated in the Threading Rules above). A simple workaround is to add code to the main thread (for example, to Application#onCreate() ), which forces early deterministic loading of AsyncTask classes:
Class.forName("android.os.AsyncTask");