Android 我想要一张照片
我想查看新的活动。我的imageview使用xmlparser。但如果我单击imageview,我的应用程序将强制关闭 这是我的代码:Android 我想要一张照片,android,android-layout,android-intent,android-webview,android-imageview,Android,Android Layout,Android Intent,Android Webview,Android Imageview,我想查看新的活动。我的imageview使用xmlparser。但如果我单击imageview,我的应用程序将强制关闭 这是我的代码: thumb_image.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { String title = ((TextView) findViewById(
thumb_image.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
String title = ((TextView) findViewById(R.id.textURL)).getText().toString();
String date = ((TextView) findViewById(R.id.dateURL)).getText().toString();
String body = ((TextView) findViewById(R.id.bodyURL)).getText().toString();
ImageView thumb_image=(ImageView)findViewById(R.id.ImageURL); // thumb image
thumb_image.buildDrawingCache();
Bitmap image= thumb_image.getDrawingCache();
Bundle extras = new Bundle();
extras.putParcelable(KEY_IMAGEURL, image);
// Starting new intent
Intent i = new Intent(getApplicationContext(), SingleMenuItemActivity.class);
i.putExtra(KEY_HEADLINE, title);
i.putExtra(KEY_ARTICLEDATE, date);
i.putExtra(KEY_BODY,body);
i.putExtras(extras);
startActivity(i);
我的singlemenuactivity代码
Intent in = getIntent();
Bundle bun = in.getExtras();
//Get XML values from previous intent
String headline = bun.getString(KEY_HEADLINE);
String date = bun.getString(KEY_ARTICLEDATE);
String Body = bun.getString(KEY_BODY);
//String image = bun.getString(KEY_IMAGEURL);
Bitmap image = (Bitmap) bun.getParcelable(KEY_IMAGEURL);
WebView browser = (WebView)findViewById(R.id.webView1);
String HTML = ......................;
browser.loadData(HTML, "text/html", "utf-8");
这是logcat我的应用程序
12-16 16:10:46.017: E/dalvikvm(19543): GC_FOR_ALLOC freed 1537K, 19% free 10221K/12579K, paused 4ms+5ms
12-16 16:10:46.017: I/dalvikvm-heap(19543): Grow heap (frag case) to 10.719MB for 660976-byte allocation
12-16 16:10:46.064: E/dalvikvm(19543): GC_FOR_ALLOC freed <1K, 19% free 10866K/13283K, paused 2ms+2ms
12-16 16:10:46.118: D/webviewglue(19543): nativeDestroy view: 0x9683f0
12-16 16:10:46.126: D/webhistory(19543): Writing Form data else {} Tag
12-16 16:10:46.126: D/webhistory(19543): Writing Form data else {} Tag
12-16 16:10:46.173: I/dalvikvm(19602): Turning on JNI app bug workarounds for target SDK version 8...
12-16 16:10:46.017:E/dalvikvm(19543):释放1537K的所有元素的GC_,19%释放10221K/12579K,暂停4ms+5ms
12-16 16:10:46.017:I/dalvikvm堆(19543):为660976字节分配将堆(frag案例)增长到10.719MB
12-16 16:10:46.064:E/dalvikvm(19543):GC_FOR_ALLOC freed避免此buildDrawingCache()方法
根据android开发者文档
调用此方法将增加内存使用,并导致视图在软件中呈现一次,从而对性能产生负面影响。
尝试其他方法在其他活动上传递图像url或图像数据尝试此
像这样更改位图编码
BitmapDrawable bitmapDrawable = ((BitmapDrawable) thumb_image.getDrawable());
Bitmap bitmap1 = bitmapDrawable .getBitmap();
示例
thumb_image.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
String title = ((TextView) findViewById(R.id.textURL)).getText().toString();
String date = ((TextView) findViewById(R.id.dateURL)).getText().toString();
String body = ((TextView) findViewById(R.id.bodyURL)).getText().toString();
BitmapDrawable bitmapDrawable = ((BitmapDrawable) thumb_image.getDrawable());
Bitmap image = bitmapDrawable.getBitmap();
Bundle extras = new Bundle();
extras.putParcelable(KEY_IMAGEURL, image);
// Starting new intent
Intent i = new Intent(this, SingleMenuItemActivity.class);
i.putExtra(KEY_HEADLINE, title);
i.putExtra(KEY_ARTICLEDATE, date);
i.putExtra(KEY_BODY,body);
i.putExtras(extras);
startActivity(i);
}
});
在单击事件中初始化您的thumb\u图像
。发布你的完整日志。这是我的完整日志。我的答案你可以得到。我的应用程序仍然强制关闭@Tamilan@user3086099SingleMenuItemActivity.java
中的第33行是什么