BaseActivity: support android 5 and 6 when clearing drawable cache
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
parent
48f796c463
commit
0c0c1acc3b
@ -120,18 +120,26 @@ public abstract class BaseActivity extends AppCompatActivity implements Topic.Su
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onTopicPublished(Topic topic) {
|
public void onTopicPublished(final Topic topic) {
|
||||||
if (topic == Application.getComponent().getThemeChangeTopic()) {
|
if (topic == Application.getComponent().getThemeChangeTopic()) {
|
||||||
try {
|
try {
|
||||||
Field f = getResources().getClass().getDeclaredField("mResourcesImpl");
|
Field f;
|
||||||
|
Object o = getResources();
|
||||||
|
try {
|
||||||
|
f = o.getClass().getDeclaredField("mResourcesImpl");
|
||||||
f.setAccessible(true);
|
f.setAccessible(true);
|
||||||
Object o = f.get(getResources());
|
o = f.get(o);
|
||||||
|
} catch (final Exception ignored) { }
|
||||||
f = o.getClass().getDeclaredField("mDrawableCache");
|
f = o.getClass().getDeclaredField("mDrawableCache");
|
||||||
f.setAccessible(true);
|
f.setAccessible(true);
|
||||||
o = f.get(o);
|
o = f.get(o);
|
||||||
|
try {
|
||||||
o.getClass().getMethod("onConfigurationChange", int.class).invoke(o, -1);
|
o.getClass().getMethod("onConfigurationChange", int.class).invoke(o, -1);
|
||||||
} catch (Exception e) {
|
} catch (final Exception ignored) {
|
||||||
Log.e(TAG, "Failed to flush icon cache", e);
|
o.getClass().getMethod("clear").invoke(o);
|
||||||
|
}
|
||||||
|
} catch (final Exception e) {
|
||||||
|
Log.e(TAG, "Failed to flush drawable cache", e);
|
||||||
}
|
}
|
||||||
recreate();
|
recreate();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user