public class MainActivity extends Activity {
protected final Handler mHandler = new Handler();
private Runnable runnable=new Runnable() {
@Override
public void run() {
Toast.makeText(MainActivity.this,”hahahaha”,Toast.LENGTH_SHORT).show();
mHandler.postDelayed(runnable,500);
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
方案推荐指数:20
能运行才怪,在oncreate里mHandler.post(runnable)
方案推荐指数:10
没有调用。
public class MainActivity extends Activity { protected final Handler mHandler = new Handler(); private Runnable runnable=new Runnable() { @Override public void run() { Toast.makeText(MainActivity.this,"hahahaha",Toast.LENGTH_SHORT).show(); } }; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mHandler.postDelayed(runnable,500); } }