嘿,我在标题中提到了这个错误。
Handler
如果正确的命令通过蓝牙发送,我有一个每 100 毫秒查看一次。如果出现这个命令,它正在做一些事情,然后ProgressDialog
应该关闭endBookingPD.dismiss();
关闭对话框后,应该删除处理程序lookForCommandHandler.removeCallbacks(tCommand);
所以这在我第一次单击按钮时对我有用。但是第二次它给了我在这条线上提到的错误endBookingPD.show();
我搜索了一些已经退出的关于这个主题的问题,但我没有找到解决我的问题的方法。
有人有想法吗?
提前致谢。
这是我的代码:
btnEndBooking.setOnClickListener(new OnClickListener() {
endBookingPD=new ProgressDialog(CheckVehicleActivity.this);
endBookingPD.setMessage(ss1);
endBookingPD.show();
endBookingPD.setCancelable(true);
lookForCommandHandler = new Handler(Looper.getMainLooper());
tCommand = new Thread() {
public void run() {
MyApplication app = (MyApplication) getApplicationContext();
if(driveOk != null){
if(driveOk.contains(DRIVE_EXIT_OK)){
// DOING SOME STUFF
exitDrive = true;
if(exitDrive == true){
if(endBookingPD != null){
endBookingPD.dismiss();
}
}
viewFlipper.setDisplayedChild(1);
lookForCommandHandler.removeCallbacks(tCommand);
}
}
if(exitDrive == false){
lookForCommandHandler.postDelayed(this, 100);
}
System.out.println("Look for Msg Handler Running!!!!!");
tCommand.start();
});
日志:
10-31 08:28:13.329: E/WindowManager(14509): Activity
com.example.amvcarsharingkit.CheckVehicleActivity has leaked window
com.android.internal.policy.impl.PhoneWindow$DecorView@41af8978 that was originally
added here
10-31 08:28:13.329: E/WindowManager(14509): android.view.WindowLeaked: Activity
com.example.amvcarsharingkit.CheckVehicleActivity has leaked window
com.android.internal.policy.impl.PhoneWindow$DecorView@41af8978 that was originally
added here
10-31 08:28:13.329: E/WindowManager(14509):
at android.view.ViewRootImpl.<init>
(ViewRootImpl.java:348)
10-31 08:28:13.329: E/WindowManager(14509): at
android.view.WindowManagerImpl.addView(WindowManagerImpl.java:267)
10-31 08:28:13.329: E/WindowManager(14509): at
android.view.WindowManagerImpl.addView(WindowManagerImpl.java:215)
10-31 08:28:13.329: E/WindowManager(14509): at
android.view.WindowManagerImpl$CompatModeWrapper.addView(WindowManagerImpl.java:140)
10-31 08:28:13.329: E/WindowManager(14509): at
android.view.Window$LocalWindowManager.addView(Window.java:537)
10-31 08:28:13.329: E/WindowManager(14509): at
android.app.Dialog.show(Dialog.java:289)
10-31 08:28:13.329: E/WindowManager(14509): at
com.example.amvcarsharingkit.CheckVehicleActivity$10$1.onClick(
CheckVehicleActivity.java:80 1)
10-31 08:28:13.329: E/WindowManager(14509): at
com.android.internal.app.AlertController$ButtonHandler.handleMessage(
AlertController.java:168)
10-31 08:28:13.329: E/WindowManager(14509): at
android.os.Handler.dispatchMessage(Handler.java:99)
10-31 08:28:13.329: E/WindowManager(14509): at
android.os.Looper.loop(Looper.java:137)
10-31 08:28:13.329: E/WindowManager(14509): at
android.app.ActivityThread.main(ActivityThread.java:4464)
10-31 08:28:13.329: E/WindowManager(14509): at
java.lang.reflect.Method.invokeNative(Native Method)
10-31 08:28:13.329: E/WindowManager(14509): at
java.lang.reflect.Method.invoke(Method.java:511)
10-31 08:28:13.329: E/WindowManager(14509): at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:822)
10-31 08:28:13.329: E/WindowManager(14509): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:589)
10-31 08:28:13.329: E/WindowManager(14509): at
dalvik.system.NativeStart.main(Native
Method)