Refresh Activity/imageview?
In my first activity I have a button and a webview and when I click on the button it opens a new activity with the content of the webview in an imageview. (I transform the webview
Solution 1:
I would highly recommend a different approach. Passing the entire bitmap through intent requires a lot of memory and wont work on older phone lets say SDK 2.3. Try passing the bitmap as a byteArray and build it for display in the next activity. If you want to pass it inbetween activities, I would store it in a file. That's more efficient, and less work for you. You can create private files in your data folder using MODE_PRIVATE that are not accessible to any other app. By the way the following worked for me:
publicvoidsendMessage(View view) {
webView.setWillNotCacheDrawing(false);
webView.destroyDrawingCache();
webView.setDrawingCacheEnabled(true);
webView.measure(MeasureSpec.makeMeasureSpec(480, MeasureSpec.EXACTLY),
MeasureSpec.makeMeasureSpec(800, MeasureSpec.EXACTLY));
webView.layout(0, 0, webView.getMeasuredWidth(), webView.getMeasuredHeight());
webView.buildDrawingCache(true);
Bitmapbmap= Bitmap.createBitmap(webView.getDrawingCache());
webView.destroyDrawingCache();
//imageView.setMaxHeight(55);//imageView.setMaxWidth(20);Bitmapbmap_New= scaleDownBitmap(bmap,400,this);
Intentintent=newIntent(this, ImageViewActivity.class);
//Bitmap b; // your bitmapByteArrayOutputStreambs=newByteArrayOutputStream();
bmap_New.compress(Bitmap.CompressFormat.PNG, 50, bs);
intent.putExtra("BitmapImage", bs.toByteArray());
//intent.putExtra("BitmapImage", bmap_New);
startActivity(intent);
}
Receiving:
publicclassImageViewActivityextendsActivity {
ImageView imageView;
@OverrideprotectedvoidonCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_image_view);
Log.d("ImageViewActivity", "Oncreate");
imageView = (ImageView) findViewById(R.id.imageView1);
//Intent intent = getIntent();//Bitmap bmp = (Bitmap)intent.getParcelableExtra("BitmapImage");if( getIntent().getExtras() != null ){
Bitmapb= BitmapFactory.decodeByteArray(
getIntent().getByteArrayExtra("BitmapImage"),0,getIntent().getByteArrayExtra("BitmapImage").length);
imageView.setImageBitmap(b);
}
else{
Log.d("ImageViewActivity", "null");
}
}
}
Post a Comment for "Refresh Activity/imageview?"