The code below shows how getWallpaper can lead to an out of memory
force close. This is the same code as I posted earlier for the
PhoneStateListener question, except getWallpaper() is used for the
background. Launch then exit (BACK) repeatedly will result in a force
close:
09-08 16:45:30.612: ERROR/AndroidRuntime(4564): Uncaught handler:
thread main exiting due to uncaught exception
09-08 16:45:30.632: ERROR/AndroidRuntime(4564):
java.lang.OutOfMemoryError: bitmap size exceeds VM budget
09-08 16:45:30.632: ERROR/AndroidRuntime(4564): at
android.graphics.BitmapFactory.nativeDecodeFileDescriptor(Native
Method)
09-08 16:45:30.632: ERROR/AndroidRuntime(4564): at
android.graphics.BitmapFactory.decodeFileDescriptor(BitmapFactory.java:
424)
09-08 16:45:30.632: ERROR/AndroidRuntime(4564): at
android.app.ApplicationContext.getCurrentWallpaperLocked
(ApplicationContext.java:523)
09-08 16:45:30.632: ERROR/AndroidRuntime(4564): at
android.app.ApplicationContext.peekWallpaper(ApplicationContext.java:
515)
09-08 16:45:30.632: ERROR/AndroidRuntime(4564): at
android.app.ApplicationContext.getWallpaper(ApplicationContext.java:
504)
09-08 16:45:30.632: ERROR/AndroidRuntime(4564): at
android.content.ContextWrapper.getWallpaper(ContextWrapper.java:201)
09-08 16:45:30.632: ERROR/AndroidRuntime(4564): at
com.example.leak.LeakExample.onCreate(LeakExample.java:37)
09-08 16:45:30.632: ERROR/AndroidRuntime(4564): at
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:
1123)
09-08 16:45:30.632: ERROR/AndroidRuntime(4564): at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:
2231)
09-08 16:45:30.632: ERROR/AndroidRuntime(4564): at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:
2284)
09-08 16:45:30.632: ERROR/AndroidRuntime(4564): at
android.app.ActivityThread.access$1800(ActivityThread.java:112)
09-08 16:45:30.632: ERROR/AndroidRuntime(4564): at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1692)
09-08 16:45:30.632: ERROR/AndroidRuntime(4564): at
android.os.Handler.dispatchMessage(Handler.java:99)
09-08 16:45:30.632: ERROR/AndroidRuntime(4564): at
android.os.Looper.loop(Looper.java:123)
09-08 16:45:30.632: ERROR/AndroidRuntime(4564): at
android.app.ActivityThread.main(ActivityThread.java:3948)
09-08 16:45:30.632: ERROR/AndroidRuntime(4564): at
java.lang.reflect.Method.invokeNative(Native Method)
09-08 16:45:30.632: ERROR/AndroidRuntime(4564): at
java.lang.reflect.Method.invoke(Method.java:521)
09-08 16:45:30.632: ERROR/AndroidRuntime(4564): at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run
(ZygoteInit.java:782)
09-08 16:45:30.632: ERROR/AndroidRuntime(4564): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:540)
09-08 16:45:30.632: ERROR/AndroidRuntime(4564): at
dalvik.system.NativeStart.main(Native Method)
On my G1 it takes ~20 launch/back cycles before the force close
happens.
Anyone have a good way of dealing with this? Is there a way to force
a GC on the system process? Would doing so resolve the problem?
Thanks,
Steve
########### here's the code (note that background uses a scale type of
'center'):
package com.example.leak;
import android.app.Activity;
import android.content.Context;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;
import android.util.Log;
import android.widget.ImageView;
public class LeakExample extends Activity {
private class MyPhoneStateListener extends PhoneStateListener {
@Override
public void onCallStateChanged(int state, String
incomingNumber) {
if ((state == TelephonyManager.CALL_STATE_RINGING)
|| (state ==
TelephonyManager.CALL_STATE_OFFHOOK)) {
LeakExample.this.finish();
}
}
}
MyPhoneStateListener phone_listener = new MyPhoneStateListener();
TelephonyManager telMgr ;
ImageView background ;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
background = (ImageView) findViewById(R.id.background);
BitmapDrawable wp = (BitmapDrawable) this.getWallpaper();
background.setImageDrawable(wp);
telMgr = (TelephonyManager) getSystemService
(Context.TELEPHONY_SERVICE);
}
@Override
protected void onPause() {
super.onPause();
telMgr.listen(phone_listener, PhoneStateListener.LISTEN_NONE);
}
@Override
protected void onResume() {
super.onResume();
telMgr.listen(phone_listener,
PhoneStateListener.LISTEN_CALL_STATE);
}
@Override
protected void onDestroy() {
super.onDestroy();
Log.v("LEAK EXAMPLE", "onDestory");
}
}
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---