skydoves / PowerMenu

:fire: Powerful and modernized popup menu with fully customizable animations.
Apache License 2.0
1.19k stars 175 forks source link

strict mode violation exception prevention #89

Open yanioaioan opened 2 years ago

yanioaioan commented 2 years ago

Please complete the following information:

Library Version 2.2.0 Android 11.0 Describe the Bug:

Using the CustomPowerMenu.Builder and having Strict mode enabled in our Android app we get StrictMode policy violation; ~duration=453 ms: android.os.strictmode.DiskReadViolation exception when trying to inflate our view

Expected Behavior:

Is it possible to provide a way of using for the CustomPowerMenu.Builder which uses AbstractPowerMenu which uses MenuPreferenceManager but NOT read or write to sharedPrefs from within MenuPreferenceManager as it currently stands, so as to avoid the StrictMode policy violation; ~duration=453 ms: android.os.strictmode.DiskReadViolation

yanioaioan commented 2 years ago

@skydoves would you be able to check my PR, please? (as it's on 'awaiting approval')

skydoves commented 2 years ago

Hi @yanioaioan, thanks for contributing to this PR. I'm just wondering if reading and writing to SharedPreferences must be run on a worker thread over Android 11. Or does only PowerMenu affects the exception? Thank you!

yanioaioan commented 2 years ago

Hi @skydoves, thanks for your response. I suppose shared prefs could potentially be accessesed on the background thread, however I am not sure is necessary to be fair. This change should temporarily be allowing disk access anyway and sort that issue anyway.

yanioaioan commented 2 years ago

Hi @skydoves , actually even my suggestion is not really solving the original problem which is touching the disk in the first place. With my suggestion we would only allow it temporarily to avoid showing the disk access violation error but the point is more lie whther we can avoid touching the disk all together, so that when we initialize the library we save one unnecessary disk access?