我是android新手。请告诉我是否有可能在5分钟,10分钟后在Android中发送Intent? 我该怎么做?
提前致谢。
答案 0 :(得分:6)
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
// Launch new Intent here
}
}, ((1000 * 60) * 5)); // 5 minutes delay before execute run()
答案 1 :(得分:3)
请参阅以下代码,它可能会对您有所帮助。使用这个计时器5分钟。
final Timer myt = new Timer();
myt.schedule(new TimerTask() {
@Override
public void run() {
// TODO Auto-generated method stub
try {
Intent intent= new Intent(currentActivity.this, new_activity.class);
startActivity(intent);
} catch (Exception e) {
// TODO: handle exception
}
myt.cancel();
}
}, 300000);
呼叫意图定时器自动终止后,在上面的代码中。
答案 2 :(得分:0)
如果操作系统决定在某个时候杀死你的应用程序,这可能会变坏。如果你真的需要在5分钟后仍然传递这个意图,你应该使用警报。看看this answer
答案 3 :(得分:-2)
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
Intent intent= new Intent(youractivity.this, activitytostart5minuteslater.class);
startActivity(intent);
}
}, ((1000 * 60) * 5));
你有没有读过评论???