android.view.WindowLeaked:Activity泄漏了最初添加的窗口com.android.internal.policy.impl.PhoneWindow $ DecorView

时间:2016-05-16 11:54:33

标签: java android

我在这行代码中不断收到此错误,无法找出根本原因

closedialog.show();

我尝试过试一试/但是错误仍然存​​在。

Runnable runnable = new Runnable() {
                        @Override
                        public void run() {
                            handler.post(new Runnable() { // This thread runs in the UI
                                @Override
                                public void run() {
                                    try{

                                    AlertDialog.Builder alert = new AlertDialog.Builder(MainActivity.this);
                                    alert.setTitle("Message");
                                    alert.setMessage(alertMessage);
                                    alert.setIcon(R.drawable.recharge_icon);
                                    //alert.show();
                                    final AlertDialog closedialog= alert.create();
                                    closedialog.show();
                                    final Timer timer2 = new Timer();
                                    timer2.schedule(new TimerTask() {
                                        public void run() {
                                            closedialog.dismiss(); 
                                            timer2.cancel(); //this will cancel the timer of the system
                                        }
                                    }, 8000); // the timer will count 5 seconds....

                                }catch(Exception ex){
                                    ex.printStackTrace();
                                }

                                }   
                           });
                        }
                    };
                    new Thread(runnable).start();
                    return

请问可能出错?

0 个答案:

没有答案