2

モバイル アプリをテストしていますが、Android エミュレーターを使用すると、アプリが頻繁にクラッシュするという問題に悩まされています。物理的な Android デバイスでは問題ありませんが、エミュレータは 1 日に数回クラッシュします。アプリの「ワークフロー」のクラッシュしやすい部分を見つけると、アプリは一貫してクラッシュします。しかし、アプリ内でクラッシュが発生する正確な場所は、バージョンによって異なるようです。

クラッシュレポートは次のとおりです。

Android: 2.3.7
Model: Full Android on x86 Emulator

java.lang.OutOfMemoryError: bitmap size exceeds VM budget
at android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:470)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:525)
at our.app.util.OurAppFileManager.getBrandingImageFromSD(OurAppFileManager.java:104)
at our.app.MainScreen.onResume(MainScreen.java:150)
at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1150)
at android.app.Activity.performResume(Activity.java:3832)
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2110)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2135)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1668)
at android.app.ActivityThread.access$1500(ActivityThread.java:117)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3683)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
at dalvik.system.NativeStart.main(Native Method)

そして、これが私のエミュレータ設定のスクリーンショットです:

エミュレータ設定

RAM と VM ヒープと内部ストレージの設定を変更しようとしましたが、うまくいきませんでした。実際、RAM の設定が高すぎると、エミュレーター ランチャーがエラーを出し始めます。

4

2 に答える 2

2

この開発者ガイドをご覧ください。

外部ソースからビットマップをデコードする際は、次のワークフローを使用します。

private Bitmap decodeFile(File f, int reqHeight, int reqWidth){
    try {
        //Decode image size
        BitmapFactory.Options o = new BitmapFactory.Options();
        o.inJustDecodeBounds = true;
        BitmapFactory.decodeStream(new FileInputStream(f),null,o);

        //Find the correct scale value. It should be the power of 2.
        int scale=1;
        while(o.outWidth/scale/2>=reqWidth && o.outHeight/scale/2>=reqHeight)
            scale*=2;

        //Decode with inSampleSize
        BitmapFactory.Options o2 = new BitmapFactory.Options();
        o2.inSampleSize=scale;
        return BitmapFactory.decodeStream(new FileInputStream(f), null, o2);
    } catch (FileNotFoundException e) {}

    return null;
}

重要な部分はinJustDecodeBoundsです。

于 2013-07-09T05:12:57.657 に答える