如何在指定时间(3 分钟)后在 android 中显示 AlertDialog
how to Display AlertDialog in android after specified time (3 min)
我想在我的 activity 中显示 AlertDialog 以向显示 "Try Again !" 的用户显示一条消息。使用 'OK' 的一个按钮。单击按钮 OK ,转到 Mainactivity
但是 AlertDialog 在 ProgressBar 完成后显示(3 分钟)
像这样的东西应该可以工作
new Thread(new Runnable(
@Override
public void run() {
try{
int progress = 0;
while (progress < 100) {
// update progressbar with handler and setProgress(progress);
Thread.sleep(3000/times);
}
}catch(Exception e) {
}
//Show dialog :)
}
}).start();
如果你想显示一个进度条,你可以使用 while(times) 并将睡眠设置为 3000/次,每次唤醒你用一个处理程序更新主线程中的进度条。
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
// Show your dialog here
}
}, 1000 * 60 * 3);
此处 postDelayed 方法获取第二个参数作为 int(以毫秒为单位的未来时间)。在指定时间后 "run" 方法将被调用。
我想在我的 activity 中显示 AlertDialog 以向显示 "Try Again !" 的用户显示一条消息。使用 'OK' 的一个按钮。单击按钮 OK ,转到 Mainactivity 但是 AlertDialog 在 ProgressBar 完成后显示(3 分钟)
像这样的东西应该可以工作
new Thread(new Runnable(
@Override
public void run() {
try{
int progress = 0;
while (progress < 100) {
// update progressbar with handler and setProgress(progress);
Thread.sleep(3000/times);
}
}catch(Exception e) {
}
//Show dialog :)
}
}).start();
如果你想显示一个进度条,你可以使用 while(times) 并将睡眠设置为 3000/次,每次唤醒你用一个处理程序更新主线程中的进度条。
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
// Show your dialog here
}
}, 1000 * 60 * 3);
此处 postDelayed 方法获取第二个参数作为 int(以毫秒为单位的未来时间)。在指定时间后 "run" 方法将被调用。