一般来说,子线程无法刷新UI界面,可以对吐司封装,让其在自线程也可以刷新
UIUtils.java
package com.itheima.mobileguard.utils;
import android.app.Activity;
import android.widget.Toast;
public class UIUtils {
public static void showToast(final Activity context,final String msg){
if("main".equals(Thread.currentThread().getName())){
Toast.makeText(context, msg, 1).show();
}else{
context.runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(context, msg, 1).show();
}
});
}
}
}