我在顯示自定義進度對話框時遇到錯誤。我用40個不同的圖像創建了進度對話框。它很好。但如果我嘗試顯示超過8-10次應用程序崩潰的對話框。帶自定義進度對話框的應用程序崩潰
錯誤日誌
09-20 13:11:12.620: E/AndroidRuntime(9156): FATAL EXCEPTION: main
09-20 13:11:12.620: E/AndroidRuntime(9156): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.spec.vespa/com.spec.vespa.view.SettingsActivity}: android.view.InflateException: Binary XML file line #13: Error inflating class <unknown>
09-20 13:11:12.620: E/AndroidRuntime(9156): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1659)
09-20 13:11:12.620: E/AndroidRuntime(9156): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1675)
09-20 13:11:12.620: E/AndroidRuntime(9156): at android.app.ActivityThread.access$1500(ActivityThread.java:121)
09-20 13:11:12.620: E/AndroidRuntime(9156): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:943)
09-20 13:11:12.620: E/AndroidRuntime(9156): at android.os.Handler.dispatchMessage(Handler.java:99)
09-20 13:11:12.620: E/AndroidRuntime(9156): at android.os.Looper.loop(Looper.java:138)
09-20 13:11:12.620: E/AndroidRuntime(9156): at android.app.ActivityThread.main(ActivityThread.java:3701)
09-20 13:11:12.620: E/AndroidRuntime(9156): at java.lang.reflect.Method.invokeNative(Native Method)
09-20 13:11:12.620: E/AndroidRuntime(9156): at java.lang.reflect.Method.invoke(Method.java:507)
09-20 13:11:12.620: E/AndroidRuntime(9156): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:878)
09-20 13:11:12.620: E/AndroidRuntime(9156): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:636)
09-20 13:11:12.620: E/AndroidRuntime(9156): at dalvik.system.NativeStart.main(Native Method)
09-20 13:11:12.620: E/AndroidRuntime(9156): Caused by: android.view.InflateException: Binary XML file line #13: Error inflating class <unknown>
09-20 13:11:12.620: E/AndroidRuntime(9156): at android.view.LayoutInflater.createView(LayoutInflater.java:518)
09-20 13:11:12.620: E/AndroidRuntime(9156): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
09-20 13:11:12.620: E/AndroidRuntime(9156): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:568)
09-20 13:11:12.620: E/AndroidRuntime(9156): at android.view.LayoutInflater.rInflate(LayoutInflater.java:623)
09-20 13:11:12.620: E/AndroidRuntime(9156): at android.view.LayoutInflater.rInflate(LayoutInflater.java:626)
09-20 13:11:12.620: E/AndroidRuntime(9156): at android.view.LayoutInflater.inflate(LayoutInflater.java:408)
09-20 13:11:12.620: E/AndroidRuntime(9156): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
09-20 13:11:12.620: E/AndroidRuntime(9156): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
09-20 13:11:12.620: E/AndroidRuntime(9156): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:207)
09-20 13:11:12.620: E/AndroidRuntime(9156): at android.app.Dialog.setContentView(Dialog.java:421)
09-20 13:11:12.620: E/AndroidRuntime(9156): at com.spec.vespa.view.SettingsActivity.onCreate(SettingsActivity.java:124)
09-20 13:11:12.620: E/AndroidRuntime(9156): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
09-20 13:11:12.620: E/AndroidRuntime(9156): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1623)
09-20 13:11:12.620: E/AndroidRuntime(9156): ... 11 more
09-20 13:11:12.620: E/AndroidRuntime(9156): Caused by: java.lang.reflect.InvocationTargetException
09-20 13:11:12.620: E/AndroidRuntime(9156): at java.lang.reflect.Constructor.constructNative(Native Method)
09-20 13:11:12.620: E/AndroidRuntime(9156): at java.lang.reflect.Constructor.newInstance(Constructor.java:415)
09-20 13:11:12.620: E/AndroidRuntime(9156): at android.view.LayoutInflater.createView(LayoutInflater.java:505)
09-20 13:11:12.620: E/AndroidRuntime(9156): ... 23 more
09-20 13:11:12.620: E/AndroidRuntime(9156): Caused by: java.lang.OutOfMemoryError: bitmap size exceeds VM budget
09-20 13:11:12.620: E/AndroidRuntime(9156): at android.graphics.Bitmap.nativeCreate(Native Method)
09-20 13:11:12.620: E/AndroidRuntime(9156): at android.graphics.Bitmap.createBitmap(Bitmap.java:477)
09-20 13:11:12.620: E/AndroidRuntime(9156): at android.graphics.Bitmap.createBitmap(Bitmap.java:444)
09-20 13:11:12.620: E/AndroidRuntime(9156): at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:349)
09-20 13:11:12.620: E/AndroidRuntime(9156): at android.graphics.BitmapFactory.finishDecode(BitmapFactory.java:521)
09-20 13:11:12.620: E/AndroidRuntime(9156): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:496)
09-20 13:11:12.620: E/AndroidRuntime(9156): at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:359)
09-20 13:11:12.620: E/AndroidRuntime(9156): at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:715)
09-20 13:11:12.620: E/AndroidRuntime(9156): at android.content.res.Resources.loadDrawable(Resources.java:1721)
09-20 13:11:12.620: E/AndroidRuntime(9156): at android.content.res.Resources.getDrawable(Resources.java:585)
09-20 13:11:12.620: E/AndroidRuntime(9156): at android.graphics.drawable.AnimationDrawable.inflate(AnimationDrawable.java:267)
09-20 13:11:12.620: E/AndroidRuntime(9156): at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:805)
09-20 13:11:12.620: E/AndroidRuntime(9156): at android.graphics.drawable.Drawable.createFromXml(Drawable.java:746)
09-20 13:11:12.620: E/AndroidRuntime(9156): at android.content.res.Resources.loadDrawable(Resources.java:1706)
09-20 13:11:12.620: E/AndroidRuntime(9156): at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
09-20 13:11:12.620: E/AndroidRuntime(9156): at android.widget.ProgressBar.<init>(ProgressBar.java:215)
09-20 13:11:12.620: E/AndroidRuntime(9156): at android.widget.ProgressBar.<init>(ProgressBar.java:170)
09-20 13:11:12.620: E/AndroidRuntime(9156): ... 26 more
我也做了一些內存管理規定如下:
public void unbindDrawables(View view) {
if (view.getBackground() != null) {
view.getBackground().setCallback(null);
}
if (view instanceof ViewGroup) {
for (int i = 0; i < ((ViewGroup) view).getChildCount(); i++) {
unbindDrawables(((ViewGroup) view).getChildAt(i));
}
try{
((ViewGroup) view).removeAllViews();
}catch (UnsupportedOperationException e) {}
}
}
什麼我失蹤?
進度條的xml:
<RelativeLayout android:layout_width="fill_parent"
android:layout_marginLeft="40dp"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:background="@drawable/progress_context">
<ProgressBar android:layout_height="100dp"
android:layout_width="100dp"
android:id="@+id/prg"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:drawingCacheQuality="low"
style="@android:style/Widget.ProgressBar.Large.Inverse"
android:indeterminateDrawable="@drawable/custom_progress_drawable"/>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/prg"
android:layout_marginTop="15dp"
android:textSize="20sp"
android:textColor="#ffffff"
android:text="@string/loading"
android:paddingBottom="10dp"
android:id="@+id/txtProgressMessage"
android:layout_centerHorizontal="true"/>
</RelativeLayout>
你能提供自定義進度對話框代碼? –
「我缺少什麼?」一些代碼... – RvdK