set timeout Dialog in android?

前端 未结 2 1415
醉梦人生
醉梦人生 2021-02-05 22:25

I want to set timeout for Dialog (progress dialog) in android , to make the dialog disappears after a period of time (if there is No response for some action !)

2条回答
  •  醉梦人生
    2021-02-05 22:29

    The same approach as in this post is verified to work (with long instead of float):

    public void timerDelayRemoveDialog(long time, final Dialog d){
        new Handler().postDelayed(new Runnable() {
            public void run() {                
                d.dismiss();         
            }
        }, time); 
    }
    

提交回复
热议问题