日志“你好”只出现一次,吐司根本没有出现..
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ScheduledExecutorService scheduler =
Executors.newSingleThreadScheduledExecutor();
scheduler.scheduleAtFixedRate(new Runnable() {
public void run() {
Log.i("hello", "world");
Toast.makeText(getApplicationContext(), "It works", Toast.LENGTH_SHORT).show();
// TODO Auto-generated method stub
}
}, 10, 10, TimeUnit.SECONDS);
}
答案 0 :(得分:9)
尝试
scheduler.scheduleAtFixedRate(new Runnable() {
public void run() {
Log.i("hello", "world");
runOnUiThread(new Runnable() {
public void run() {
Toast.makeText(getApplicationContext(), "It works", Toast.LENGTH_SHORT).show();
}
});
}
}, 10, 10, TimeUnit.SECONDS);