在运行异步任务时禁用android中的主页按钮

时间:2012-04-02 06:35:38

标签: android

我需要在运行我创建的异步任务时禁用或禁用我的Android手机的主页按钮。请在中断异步任务时查看我收到的错误日志。

01-01 01:09:39.375: ERROR/WindowManager(1415): Activity  com.android.settings.ThemePreview has leaked window  com.android.internal.policy.impl.PhoneWindow$DecorView@418cb518 that was originally added here
01-01 01:09:39.375: ERROR/WindowManager(1415): android.view.WindowLeaked: Activity com.android.settings.ThemePreview has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@418cb518 that was originally added here
01-01 01:09:39.375: ERROR/WindowManager(1415):     at android.view.ViewRootImpl.<init>(ViewRootImpl.java:350)
01-01 01:09:39.375: ERROR/WindowManager(1415):     at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:245)
01-01 01:09:39.375: ERROR/WindowManager(1415):     at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:193)
01-01 01:09:39.375: ERROR/WindowManager(1415):     at android.view.WindowManagerImpl$CompatModeWrapper.addView(WindowManagerImpl.java:118)
01-01 01:09:39.375: ERROR/WindowManager(1415):     at android.view.Window$LocalWindowManager.addView(Window.java:537)
01-01 01:09:39.375: ERROR/WindowManager(1415):     at android.app.Dialog.show(Dialog.java:279)
01-01 01:09:39.375: ERROR/WindowManager(1415):     at com.android.settings.ThemePreview$ApplyTheme.onPreExecute(ThemePreview.java:357)
01-01 01:09:39.375: ERROR/WindowManager(1415):     at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:561)
01-01 01:09:39.375: ERROR/WindowManager(1415):     at android.os.AsyncTask.execute(AsyncTask.java:511)
01-01 01:09:39.375: ERROR/WindowManager(1415):     at com.android.settings.ThemePreview.onOptionsItemSelected(ThemePreview.java:239)
01-01 01:09:39.375: ERROR/WindowManager(1415):     at android.app.Activity.onMenuItemSelected(Activity.java:2502)
01-01 01:09:39.375: ERROR/WindowManager(1415):     at com.android.internal.policy.impl.PhoneWindow.onMenuItemSelected(PhoneWindow.java:961)
01-01 01:09:39.375: ERROR/WindowManager(1415):     at com.android.internal.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:735)
01-01 01:09:39.375: ERROR/WindowManager(1415):     at com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:149)
01-01 01:09:39.375: ERROR/WindowManager(1415):     at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:874)
01-01 01:09:39.375: ERROR/WindowManager(1415):     at com.android.internal.view.menu.ActionMenuView.invokeItem(ActionMenuView.java:490)
01-01 01:09:39.375: ERROR/WindowManager(1415):     at com.android.internal.view.menu.ActionMenuItemView.onClick(ActionMenuItemView.java:103)
01-01 01:09:39.375: ERROR/WindowManager(1415):     at android.view.View.performClick(View.java:3480)
01-01 01:09:39.375: ERROR/WindowManager(1415):     at android.view.View$PerformClick.run(View.java:13993)
01-01 01:09:39.375: ERROR/WindowManager(1415):     at android.os.Handler.handleCallback(Handler.java:605)
01-01 01:09:39.375: ERROR/WindowManager(1415):     at android.os.Handler.dispatchMessage(Handler.java:92)
01-01 01:09:39.375: ERROR/WindowManager(1415):     at android.os.Looper.loop(Looper.java:137)
01-01 01:09:39.375: ERROR/WindowManager(1415):     at android.app.ActivityThread.main(ActivityThread.java:4368)
01-01 01:09:39.375: ERROR/WindowManager(1415):     at java.lang.reflect.Method.invokeNative(Native Method)
01-01 01:09:39.375: ERROR/WindowManager(1415):     at java.lang.reflect.Method.invoke(Method.java:511)
01-01 01:09:39.375: ERROR/WindowManager(1415):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
01-01 01:09:39.375: ERROR/WindowManager(1415):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
01-01 01:09:39.375: ERROR/WindowManager(1415):     at dalvik.system.NativeStart.main(Native Method)

3 个答案:

答案 0 :(得分:3)

首页按钮无法被禁用。这是Android的安全原则的一部分,用户应该能够最小化应用程序并随时进入主屏幕。它也是Android ia多任务处理必不可少的。你需要改变你的逻辑以适应这种情况。就个人而言,我不相信应用程序。哪个不让我进入主屏幕并启动我选择的应用程序。

答案 1 :(得分:0)

因此我们无法禁用主页按钮 在Android SDK中,只要按HOME键,app就会最小化并启动主屏幕 所以我们不能有任何与Home Key相关的事件。

答案 2 :(得分:0)

在您的活动中使用以下覆盖方法:

@Override
public void onAttachedToWindow()
{  
       this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);     
       super.onAttachedToWindow();  
}