【Android】「cannot perform this action inside of onloadfinished」エラーの対処法

非同期処理が終わったタイミングで実行しようとした処理で「cannot perform this action inside of onloadfinished」というエラーが発生しています。

このエラーはGUIに関する操作をメインスレッド以外のスレッドから行おうとした場合に発生するものです。

このエラーを解消するためには以下のソースコードを記述します。

エラー解消方法


import android.os.Handler;
import android.os.Looper;

Handler handler = new Handler(Looper.getMainLooper());
    handler.post(new Runnable() {
        @Override
        public void run() {
            // GUIに関する処理を記述
        }
    });

参考サイト:

Android アプリ開発で “cannot perform this action inside of onloadfinished” とエラーメッセージが表示された場面の対処法