Sunday, July 17, 2022

[FIXED] How to manually enable android hardware acceleration after setContentView?

Issue

In my SplashActivity, sometimes it will display a image view , and sometimes it will display gif. I use android-gif-drawable to play gif. But I found, if I don't set activity <activity android:hardwareAccelerated="true" />, gif will play under normal rate. Only I enable hardwareAccelerated, it plays normal. However, after I set <activity android:hardwareAccelerated="true" />, I use adb shell dumpsys com.yanzi.demo found, GL cost about 20M memory. So, I must use java to enable hardware accelerate, only when play gif.

I use next code to enable it:

getWindow().setFlags(
    WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED,
    WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED);

write it before setContentView works well. But, it takes time for me to check whether play gif or not, so it must be enabled after setContentView. I test it, found don't work. Someone can help me? Or, this is a problem with no way? Api guides


Solution

If you enable hardware accelerated that way after setContentView, you must use WindowManager to add view. Otherwise, it will not work at all. Hope to help you.



Answered By - user6613094
Answer Checked By - Marie Seifert (PHPFixing Admin)

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.