如何在指定时间(3分钟)后在android中显示AlertDialog
我想在我的活动中为显示“重试!”的用户消息显示AlertDialog。使用一个“确定”按钮。单击“确定”按钮后,转到Mainactivity如何在指定时间(3分钟)后在android中显示AlertDialog,android,android-alertdialog,Android,Android Alertdialog,我想在我的活动中为显示“重试!”的用户消息显示AlertDialog。使用一个“确定”按钮。单击“确定”按钮后,转到Mainactivity 但是完成进度条后显示AlertDialog(3分钟)类似的功能应该可以工作 new Thread(new Runnable( @Override public void run() { try{ int progress = 0; while (progress < 1
但是完成进度条后显示AlertDialog(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();
新线程(新的可运行线程)(
@凌驾
公开募捐{
试一试{
int progress=0;
而(进度<100){
//使用handler和setProgress(进度)更新progressbar;
线程。睡眠(3000次/次);
}
}捕获(例外e){
}
//显示对话框:)
}
}).start();
如果希望显示进度条,可以使用while(times)并将sleep设置为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”方法。您应该分别搜索两件事,即如何延迟和如何显示警报。我知道如何显示警报,但我正在寻找如何延迟:)有很多方法,我建议使用
postDelayed来搜索类似于处理程序的东西(Runnable Runnable,long duration)
方法发布alertDialog,其中持续时间为TimeUnit.MINUTES。toMillis(3)
alertDialog将在进度条结束后出现?