androideclipseandroid-studioui-threadbringtofront

Android Studio - bringToFront must be called from the UI thread


since I've imported my Eclipse project to Android Studio I have an error concerning the bringToFront() method.

protected Void doInBackground(String... num_t) {

        planningTitle = (TextView) findViewById(R.id.planningTitle);

        planningTitle.bringToFront(); /* Bring Planning Title in front of Table Layout */

        /* Plubish the result to update Layout */
        publishProgress(num_t[0]);

        return null;
    }

I saw some similar questions concerning getText() method and understood them but I can't figured out what to do with this bringToFront() method.

Error : Method bringToFront must be called from UI thread, currently inferred thread is worker...

The project is compiling anyway but I'm curious to know where is my mistake.

Thanks in advance. C.


Solution

  • Generally you shouldn't execute UI related code in doInBackground, you should move UI related code to onPostExecute or onProgressUpdate methods of your AsyncTask.

    There are ways to do it, though. This answer might help you:

    Android : Calling the methods on UI thread from AsyncTask doInBackground method