Yep 150kb image est trop .... vous devez le redimensionner de sorte que l'androïde allouer la mémoire en fonction des besoins. Il empêche le plantage de l'application OOM.
int resolution=100;
profileImageViewNav.setImageBitmap(decodeSampledBitmapFromResource(getResources(),R.drawable.profile_image, resolution, resolution));
Voici decodeSampledBitmapFromResource() fonction
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);
}
Et voici le code de fonction calculateInSampleSize()
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;
}
'lors du chargement de quelques images (150kb un) est correct ou trop?' ** Evidemment ça ne dépend pas de leur taille "sur disque" ... ** ... * Je me demandais pourquoi mon application ne fonctionnerait pas sur le téléphone de mon ami * ... alors essayez ... Où est la question ? – Selvin
'Est-il possible d'exécuter l'application qui a besoin de 180 Mo de RAM sur le téléphone qui au moment de l'exécution a ~ 130 Mo de RAM libre?' - mon problème principal. Un autre: Est-il possible de forcer le téléphone à effacer la RAM afin que mon application puisse fonctionner? – Filemon279
* Est-il possible de forcer le téléphone à effacer la RAM * oui, disposer des bitmaps inutiles et gc ferait cela ... – Selvin