1、来个简单的,该面壁思过的
public class Play2 {
private static int a = 0;
private static int b = 0;
public static void main(String[] args) {
a = ++a;
System.out.println(a);// a = 1
for(int i = 0;i<30;i++){
b = b++;
System.out.println(b);// b = 0(一直为0)
}
}
}
2、欢迎界面的页面切换
应该在子线程中根据页数决定是否发送消息给主线程更新图片
而不应该子线程发送消息,主线程里判断页数,这样无法控制发送消息的次数
new Thread() {
@Override
public void run() {
super.run();
while (flag) {
if(a<3){
handler.sendEmptyMessage(0);
SystemClock.sleep(1000);
}else{
flag = false;
Intent intent = new Intent(WelcomeActivity.this,MainActivity.class);
startActivity(intent);
finish();
}
}
}
}.start();
handler:
private Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
switch (msg.what) {
case 0:
iv.setImageResource(resID[a++]);
break;
}
}
};