wasabeef / Takt

Takt is Android library for measuring the FPS using Choreographer.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

FPS text only shows for a few seconds (then disappears) in Android 7.1

arshcaria opened this issue · comments

Google changed the behavior of LayoutParams.TYPE_TOAST in Android 7.1.
https://android.googlesource.com/platform/frameworks/base/+/dc24f93

So on 7.1 devices the FPS text cannot not stay on the screen.

You can add version check as follow,and it will wrok well.

    if(  Build.VERSION.SDK_INT <21) {
      params.type = WindowManager.LayoutParams.TYPE_PRIORITY_PHONE;
    }else if( Build.VERSION.SDK_INT <24) {
      params.type = WindowManager.LayoutParams.TYPE_TOAST;
    }else {
      params.type = WindowManager.LayoutParams.TYPE_SYSTEM_ALERT;
    }

catch exception when loading tinker:java.lang.RuntimeException: Unable to create application com.tencent.radio.RadioApplication: android.view.WindowManager$BadTokenException: Unable to add window -- window android.view.ViewRootImpl$W@8ca0794 has already been added
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5406)
at android.app.ActivityThread.-wrap2(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1545)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
Caused by: android.view.WindowManager$BadTokenException: Unable to add window -- window android.view.ViewRootImpl$W@8ca0794 has already been added
at android.view.ViewRootImpl.setView(ViewRootImpl.java:691)
at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:342)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:93)
at jp.wasabeef.takt.Takt$Program.play(Takt.java:113)
at com.tencent.radio.RadioApplicationDelegate.initTakt(RadioApplicationDelegate.java:122)
at com.tencent.radio.RadioApplicationDelegate.onCreate(RadioApplicationDelegate.java:111)
at com.tencent.tinker.loader.app.TinkerApplication.onCreate(TinkerApplication.java:173)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1024)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5403)
at android.app.ActivityThread.-wrap2(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1545) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:154) 
at android.app.ActivityThread.main(ActivityThread.java:6119) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776) 

7.1.1 直接crash了