My project was working until I updated my S6 Edge to Android 6.0.1.
The app crashes with an OutOfMemory error after the second launch.
The application contains 2000+ images in the directory and I am using a timer to increment a counter and display them on an imageView. When onFinish()/onPause()/onDestroy() is called I am destroying/cancelling all the objects such as the timers, counter and imageView by setting them to null.
This is how I am fetching/printing the image to the imageView
int resID = getResources().getIdentifier("animation"+i , "drawable", getPackageName());
Drawable animationFrame = ContextCompat.getDrawable(this, resID);
animationView.setImageDrawable(animationFrame);
i++;
It runs on initial launch (even if I install the app using a generated APK). When I remove the app from the minimised applications, the application crashes after 2-3 seconds. I have checked the memory allocated and it is normal (up to 12MB) on the first run whereas on the second the memory allocated is 255MB.
onDestroy() method This includes ALL my variables initialised. My variables are initialised as private or with no access variable.
@Override
protected void onDestroy() {
super.onDestroy();
pauseAnimation();
animationView.setImageDrawable(null);
animationView = null;
justAnimation = null;
buttonSign = null;
i = 0;
media.stop();
media = null;
deathRateEU = 0;
deathRateUK = 0;
labelNumber = null;
labelNumberUK = null;
buttonSign = null;
loadingEU = null;
loadingUK = null;
}
Media is a MediaPlayer initialised as public and it plays a sound when counter(i) reaches a point
I installed this on another device that runs Android 5.1.3 (not sure but it is 5.1 something).
Is there is a known bug for OutOfMemory issues when application get minimised on Android 6.0.1?
I am 100% sure that I did not make any changes before/after my phone updated to version 6.0.1
Notes:
- If the application is already installed on the device and I try to compile it using Android Studio, the crash occurs
- I have to uninstall/re-compile to manage to get the app working in the first go
- I get the same error when I try to run my project on a Genymotion Android 6.0 device, but not on an Android 5.1 genymotion virtual device
finish();
??? In onDestroy() ? – LitmusanimationView.setImageResource(resId);
so you dont have to make that Drawable. – Litmus