I am facing too many crashes in Kids ABCD application and that too because of Inflate Exceptions which was arising due to OUT OF MEMORY ERROR.
Application is taking so much space, when it is running in foreground, causing it to crash.
This problem arises only when we are switching between different activities so rapidly that the heap area gets filled so fast and application begins to give inflate exception and crash eventually before the space freed on activity destroy. (Rapid switching between activities is done to check the app performance).
The main cause could be large images or application taking more space in cache background storage.
Large size images could not be the problem as we already verified that all images should be of moderate size. Another thing that we had done with the code is that we have finished each activity on each intent by calling finish()
method. Here finish()
method is used so that the activity could release all the bitmaps from current space (on closing the activity).
super.onCreate(savedInstanceState);
setContentView(R.layout.ringa_ringa);
pause = (ImageView) findViewById(R.id.pause);
txt = (TextView) findViewById(R.id.txt);
pause.setVisibility(View.VISIBLE);
txt.setTextColor(Color.parseColor("#ffffff"));
list = new ArrayList<>();
mediaStorageDir = new File(Environment.getExternalStorageDirectory(), "Kids_Rhymes");
ringa_thread_running = false;
pause.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (counter == 0) {
mediaPlayer.stop();
ringa_thread_running = false;
position = 0;
if (lyrics_ring.isAlive()) {
lyrics_ring.interrupt();
}
pause.setImageResource(R.drawable.play);
counter = 1;
} else if (counter == 1) {
pause.setImageResource(R.drawable.pause);
counter = 0;
onResume();
}
}
});
String[] words = getResources().getString(R.string.ringa).split("\\$");
for (String w : words) {
System.out.println("=======String====" + w);
list.add(w);
}
Tried to find out the accurate solution for this but didn't get the suitable one.