A1:在应用程序中,我加载了服务器的4 个base64 字符串并在应用程序中创建缩略图。为它们创建视图并将它们添加到滚动布局中。到目前为止没有任何问题。
A1-A1-A1++ 如果我一次又一次地重复 A1 - 在布局中添加 5 个图像和 5 个更多图像...... - 没问题。
A2:仍在应用程序中 - 与主要活动相反。进入一项新活动 - 图片选择活动。从应用程序选择部分的图库中加载图像。创建图像预览。到目前为止没有任何问题。
A2-A2-A2++ 如果我在此之后一次又一次地重复 A2 - 没问题。
A1-A2-A2-A2++ 如果我做 A1 并一次又一次地重复 A2 - 没问题。
A1-A2-A1-A2 如果我从 A1 开始并执行 A2 并返回 A1 然后 A2,它应该在创建预览图像时崩溃。
A1:
int count = 1;
while (count < 5)
{
try {
TelephonyManager mngr = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
String imei = mngr.getDeviceId();
String image_count = String.valueOf(count);
String user_image = new GetUserImagesActivity().execute(imei,image_count).get();
byte[] decodedString = Base64.decode(user_image, Base64.DEFAULT);
Bitmap decodedByte = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length);
/*BitmapDrawable ob = new BitmapDrawable(decodedByte);*/
//ImageView Setup
ImageView imageView1 = new ImageView(this);
imageView1.setTag(count);
imageView1.setOnTouchListener(this);
//setting image resource
imageView1.setImageBitmap(decodedByte);
//setting image position
LinearLayout.LayoutParams params2 = new LinearLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
params2.gravity=Gravity.CENTER_HORIZONTAL;
params2.gravity=Gravity.CENTER_VERTICAL;
imageView1.setLayoutParams(params2);
imageView1.setAdjustViewBounds(true);
imageView1.setMaxHeight(240);
imageView1.setMaxWidth(180);
/*imageView.setMinimumHeight(180);
imageView.setMinimumWidth(240);*/
imageView1.setId(110011);
imageView1.setPadding(5, 0, 5, 0);
//adding view to layout
top_container.addView(imageView1);
count++;
//Tried this to solve the problem//
imageView1.setDrawingCacheEnabled(true);
imageView1.buildDrawingCache();
//Causes images to get black//
/*decodedByte.recycle();*/
} catch (InterruptedException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
Toast.makeText( getApplicationContext(), "problem 1" , Toast.LENGTH_LONG ).show();
} catch (ExecutionException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
Toast.makeText( getApplicationContext(), "problem 2" , Toast.LENGTH_LONG ).show();
}
}
A2: - 新图像到服务器(预览失败)
cursor.moveToFirst();
int idx = cursor.getColumnIndex(ImageColumns.DATA);
String fileSrc = cursor.getString(idx);
bitmap = BitmapFactory.decodeFile(fileSrc);
// load // preview // image
bitmap = Bitmap.createScaledBitmap(bitmap, 480, 640, false);
// bmpDrawable = new BitmapDrawable(bitmapPreview);
img_logo.setImageBitmap(bitmap);
日志:
11-08 16:44:58.293: D/dalvikvm(22771): GC_BEFORE_OOM freed 44K, 34% free 22390K/33571K, paused 23ms
11-08 16:44:58.293: E/dalvikvm-heap(22771): Out of memory on a 36000016-byte allocation.
11-08 16:44:58.303: W/dalvikvm(22771): threadid=1: thread exiting with uncaught exception (group=0x40a9f210)
11-08 16:44:58.303: E/AndroidRuntime(22771): FATAL EXCEPTION: main
11-08 16:44:58.303: E/AndroidRuntime(22771): java.lang.OutOfMemoryError
11-08 16:44:58.303: E/AndroidRuntime(22771): at android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
11-08 16:44:58.303: E/AndroidRuntime(22771): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:499)
11-08 16:44:58.303: E/AndroidRuntime(22771): at android.graphics.BitmapFactory.decodeFile(BitmapFactory.java:305)