2016-09-05 9 views
0

ボタンをクリックして2番目のアクティビティに移動しようとするとクラッシュする(残念ながらアプリが停止した)。主要アクティビティと第2アクティビティは背景イメージで作成されました。大きな背景で新しいアクティビティを開始するとクラッシュするアプリケーション

私は背景を削除してmipmapに置き換えようとしましたが、クラッシュすることなくアプリがうまく動作するようにしました。どうしてか分かりません ? PS:バックラウンドのサイズjpg = 70kbおよび80kb。

look at the java main & drawable folder

+2

Loading Large Bitmaps Efficientlyから取得する代わりに、あなたのコードのスクリーンショットを掲載される。ここ

ImageViewにロードする前に、その画像を縮小クラッシュからのスタックトレースと一緒に、ここで実際の関連するコードを貼り付ける必要があります。 – codeMagic

+0

'ios'ですか?アンドロイドスタジオ?無関係なタグで迷惑メールしないでください! –

答えて

3

あなたが説明したように、私は、例外がOutOfMemory例外であると思います。これは、大きなイメージをアクティビティに読み込む際によく知られている問題です。あなたは、サンプルコードは

public static int calculateInSampleSize(
      BitmapFactory.Options options, int reqWidth, int reqHeight) { 
    // Raw height and width of image 
    final int height = options.outHeight; 
    final int width = options.outWidth; 
    int inSampleSize = 1; 

    if (height > reqHeight || width > reqWidth) { 

     final int halfHeight = height/2; 
     final int halfWidth = width/2; 

     // Calculate the largest inSampleSize value that is a power of 2 and keeps both 
     // height and width larger than the requested height and width. 
     while ((halfHeight/inSampleSize) >= reqHeight 
       && (halfWidth/inSampleSize) >= reqWidth) { 
      inSampleSize *= 2; 
     } 
    } 

    return inSampleSize; 
} 

public static Bitmap decodeSampledBitmapFromResource(Resources res, int resId, 
     int reqWidth, int reqHeight) { 

    // First decode with inJustDecodeBounds=true to check dimensions 
    final BitmapFactory.Options options = new BitmapFactory.Options(); 
    options.inJustDecodeBounds = true; 
    BitmapFactory.decodeResource(res, resId, options); 

    // Calculate inSampleSize 
    options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight); 

    // Decode bitmap with inSampleSize set 
    options.inJustDecodeBounds = false; 
    return BitmapFactory.decodeResource(res, resId, options); 
} 
関連する問題