Android几秒后自动关闭dialog

代码改变世界

Android几秒后自动关闭dialog

AlertDialog.Builder builder = new AlertDialog.Builder(v.getContext());
                builder.setTitle("发送成功!");
                builder.setMessage("2秒后自动关闭!");
                builder.setCancelable(true);
                final AlertDialog dlg = builder.create();
                dlg.show();
                final Timer t = new Timer();
                t.schedule(new TimerTask() {
                    public void run() {
                        Intent intent1 = new Intent();
                        intent1.setClass(InquirySheetListActivity.this, MainActivity.class);
                        startActivity(intent1);
                        finish();
                        dlg.dismiss();
                        t.cancel();
                    }
                }, 2000);

 

AlertDialog.Builder builder = new AlertDialog.Builder(v.getContext());
builder.setTitle("发送成功!");
builder.setMessage("2秒后自动关闭!");
builder.setCancelable(true);
final AlertDialog dlg = builder.create();
dlg.show();
final Timer t = new Timer();
t.schedule(new TimerTask() {
public void run() {
Intent intent1 = new Intent();
intent1.setClass(InquirySheetListActivity.this, MainActivity.class);
startActivity(intent1);
finish();
dlg.dismiss();
t.cancel();
}
}, 2000);
posted @ 2017-11-13 11:26  改变世界的老十七  阅读(8317)  评论(1编辑  收藏  举报