本文介绍了Android中的TimerTask的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好
我想在我的android设备上的imageviewer上显示欢迎图片,三秒钟后我想更改活动并将用户发送到程序的其他部分,但是TimerTask似乎不起作用!有人可以帮我吗?
Hi guys
i want to show a welcome picture on imageviewer in my android device and after 3seconds i want to change the activity and send user to some other part of program but my TimerTask seems not working! can any one help me?
public class TicketFinalActivity extends Activity {
ImageView iv;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Timer t = new Timer();
TimerTask welcome = new TimerTask(){
@Override
public void run() {
// TODO Auto-generated method stub
Intent intent = new Intent(TicketFinalActivity.this,Caution.class);
startActivity(intent);
}
};
t.schedule(welcome, 300, 30000);
iv = (ImageView)findViewById(R.id.GreetView);
}
}
推荐答案
public class TicketFinalActivity extends Activity {
private final int DELAY_TIME = 1000;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
new Timer().schedule(new TimerTask() {
@Override
public void run() {
try {
Intent i= new Intent(TicketFinalActivity.this, Caution.class);
startActivity(i);
}
catch (Exception e) {
Log.i("TAG", "Error: " + e.getMessage());
finish();
}
}
}, DELAY_TIME);
}
这篇关于Android中的TimerTask的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!