I have a launcher Activity
that load and resize big bitmap as it\'s background when it opens.
Whenever hit the back button, the Activity
is
try to finish the activity when pressing back button
@Override
public void onBackPressed() {
super.onBackPressed();
finish();
}
Add following code for it
@Override
protected void onDestroy() {
//android.os.Process.killProcess(android.os.Process.myPid());
super.onDestroy();
if(scaledBitmap!=null)
{
scaledBitmap.recycle();
scaledBitmap=null;
}
}
Finishing an Activity doesn't clear its memory. It only removes the Activity from its stack, Android will clear its memory when it needs memory (garbage collection),if you face memory issue from drawable,
even after destroying the activity by calling finish(), it's resources are queued for garbage collection. activity will be freed during next GC cycle.
@Override
public void onDestroy() {
super.onDestroy();
Runtime.getRuntime().gc();
}
You can also use android:largeHeap="true"
to request a larger heap size, in your application tag in manifest.
add this to your code
@Override
public boolean onKeyDown(int keyCode, KeyEvent event)
{
if ((keyCode == KeyEvent.KEYCODE_BACK))
{
finish();
}
return super.onKeyDown(keyCode, event);
}
Try to set the bitmap to null while activity is destroyed and if desire run the garbage collector.