主线程中延时启动dialog

主线程中延时启动dialog

错误的:

        new Thread(new Runnable() {
            public void run() {
                try {
                    Thread.sleep(5000);
                    showToMemberDialog();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }).start();



正确的:

		final Handler handler=new Handler(){
			@Override
			public void handleMessage(Message msg) {
				showToMemberDialog();
				super.handleMessage(msg);
			}
		};

		Thread thread=new Thread(){
			public void run() {
				//这里处理耗时操作,比如文件下载等等
				try {
					Thread.sleep(5000);
				} catch (InterruptedException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				handler.sendEmptyMessage(0);
			};
		};
		thread.start();

或者:

		mHandler.postDelayed(new Runnable() {
			public void run() {
				if (!isFinishing()) {
					showToMemberDialog();
				}
			}
		}, 15000);


你可能感兴趣的:(Android)