Android.view.WindowManager $ BadTokenException:

时间:2017-06-25 21:12:14

标签: android locking screen

我正在开发一个Screen Lock应用程序 它在某些设备上运行正常,但在某些情况下我收到此错误

  

了java.lang.RuntimeException:
        在android.app.ActivityThread.handleServiceArgs(ActivityThread.java:3209)
        在android.app.ActivityThread.access $ 2200(ActivityThread.java:150)
        在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1505)
        在android.os.Handler.dispatchMessage(Handler.java:102)
        在android.os.Looper.loop(Looper.java:168)
        在android.app.ActivityThread.main(ActivityThread.java:5845)
        at java.lang.reflect.Method.invoke(Native Method:0)
        在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:797)
        在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:687)
      引起:android.view.WindowManager $ BadTokenException:
        在android.view.ViewRootImpl.setView(ViewRootImpl.java:609)
        在android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:310)
        在android.view.WindowManagerImpl.addView(WindowManagerImpl.java:85)
        at com.ingilizceogren.sloth.KilitUygulamasi.KilitUygulamasiKontrol.setLockScreenToWindow(KilitUygulamasiKontrol.java:150)
        在com.ingilizceogren.sloth.KilitUygulamasi.KilitUygulamasiKontrol.lock(KilitUygulamasiKontrol.java:90)
        在com.ingilizceogren.sloth.KilitUygulamasi.KilitUygulamasiServisi.onStart(KilitUygulamasiServisi.java:63)
        在android.app.Service.onStartCommand(Service.java:459)
        在android.app.ActivityThread.handleServiceArgs(ActivityThread.java:3170)

1 个答案:

答案 0 :(得分:0)

确保您的活动正在运行,请使用

if(mActivity != null && !mActivity.isFinishing())

检查您何时致电com.ingilizceogren.sloth.KilitUygulamasi.KilitUygulamasiKontrol.setLockScreenToWindow()