Skip to content Skip to sidebar Skip to footer

Running On Uithread And Posting To View, Still Get Calledfromwrongthreadexception

Title says it all. Well mostly. This is only happening on 1 device. Other devices are fine. In the onPostExecute of a AsyncTask I am calling the code below, before getting this exc

Solution 1:

For the future if people have this issue, which you wont in any post JellyBean devices, this is how you fix it.

The very very very first thing you do in your app is this.

@OverrideprotectedvoidonCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    this.requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.activity_splash);

    this.runOnUiThread(newRunnable()
    {
        @Overridepublicvoidrun()
        {
            newAsyncInitLooperTask().execute();
        }
    });
     }

publicclassAsyncInitLooperTaskextendsAsyncTask<Void, Void, Void>
{
    @OverrideprotectedVoiddoInBackground(Void... params)
    {
        returnnull;
    }
}

What this will do it attach the InternalHandler that deals with AsyncTasks for you app to the correct Looper/UIThread that your app is using.

Post a Comment for "Running On Uithread And Posting To View, Still Get Calledfromwrongthreadexception"