In my app, I'm giving user the feature to set an image for the app's homescreen background(from gallery). The app works fine if the image if low resolution but if the user sets a high resolution image the app crashes on startup giving this error.
android.view.WindowManager$BadTokenException: Unable to add window -- token android.os.BinderProxy@35f21ac is not valid; is your activity running?
I used the override method of glide to reduce the resolution of the image:
Glide.with(MainActivity.this).asBitmap()
.apply(new RequestOptions().diskCacheStrategy(DiskCacheStrategy.RESOURCE).dontAnimate())
.load(storageUtil.getWallpaperStatus())
.apply(new RequestOptions().override(320,640).centerCrop())
.into(viewPagerBackground);
Now, the crash frequency has reduced, but still sometimes the app crashes.
What could be the best solution for this problem?