80,472
社区成员




气泡("1");
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
气泡("3");
}
},1000);
import android.annotation.SuppressLint;
import android.content.Context;
import android.os.Handler;
import android.os.Message;
import android.widget.Toast;
import androidx.annotation.NonNull;
import static java.lang.Thread.sleep;
public class Test {
private static final int FIRST = 0x01;
private static final int SECOND = 0x02;
@SuppressLint("StaticFieldLeak")
private static Context context;
private Test(Context mContext) {
context = mContext;
}
private static Handler handler = new Handler(new Handler.Callback() {
@Override
public boolean handleMessage(@NonNull Message msg) {
if (msg.what == FIRST) {
Toast.makeText(context, "11111", Toast.LENGTH_SHORT).show();
} else if (msg.what == SECOND) {
Toast.makeText(context, "22222", Toast.LENGTH_SHORT).show();
}
return false;
}
});
private static void Test() {
new Thread(() -> {
handler.sendEmptyMessage(FIRST);
try {
sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
handler.sendEmptyMessage(SECOND);
}).start();
}
}
这个你试试。