Android

1:

2:Toast show()刷新ui必须在ui主线程中调用

开发中比较好的方式是,实现工具类

public class Uitilty {

    //-->>>Toast show 必须在UI主线程中使用,封装showToast方法,获取UI 主线程Handler.post(Runnable-->Toast.show)
    public static void showToast(final Context context, final CharSequence text, final int duration){
        getMainHandler().post(new Runnable() {
            @Override
            public void run() {
                Toast.makeText(context,text,duration);
            }
        });
    }
    //<<<---
    public static Handler getMainHandler(){
        Looper main_looper=Looper.getMainLooper();
        return new Handler(main_looper);
    }
}
View Code
原文地址:https://www.cnblogs.com/conncui/p/4313123.html