Pass Bitmap Data Between Activities in Android

Pass Bitmap Data Between Activities in Android - Hello friend inabnomaniiyaha, In the article that you read this time with the title Pass Bitmap Data Between Activities in Android, we have prepared this article well for you to read and take information in it. hopefully the contents of the post what we write you can understand. Alright, happy reading.

Judul : Pass Bitmap Data Between Activities in Android
link : Pass Bitmap Data Between Activities in Android

Baca juga


Pass Bitmap Data Between Activities in Android

Pass Bitmap Data Between Activities in Android

Start New Activity from Current Activity
    Intent anotherIntent = new Intent(this, anotherActivity.class);
    startActivity(anotherIntent);
    finish();
Start New Acticity from Current Activity With Passing Required Data
    Intent anotherIntent = new Intent(this, anotherActivity.class);
    anotherIntent.putExtra("key", "value");
    startActivity(anotherIntent);
    finish();
putExtra() method is used to send extra data from one activity to another.
Extract Data In Other Activity
    data = getIntent().getStringExtra("key");
getIntent() method returns the intent that started this activity.
getStringExtra() retrieves extended data from the intent.
Pass Bitmap Data Between Activities in Android

Now, it turns out that it’s not possible to pass Bitmap as extended data. It needs to be converted to byteArray.
Pass Bitamp as Extended Data
    ByteArrayOutputStream bStream = new ByteArrayOutputStream();
    bitmap.compress(Bitmap.CompressFormat.PNG, 100, bStream);
    byte[] byteArray = bStream.toByteArray();
    Intent anotherIntent = new Intent(this, anotherActivity.class);
    anotherIntent.putExtra("image", byteArray);
    startActivity(anotherIntent);
    finish();
Retrieve Bitmap in Other Activity
    Bitmap bmp;
    byte[] byteArray = getIntent().getByteArrayExtra("image");
    bmp = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length);


That's the articlePass Bitmap Data Between Activities in Android

That's it for the article Pass Bitmap Data Between Activities in Android this time, hopefully can be useful for all of you. well, see you in another article post.

You are now reading the articlePass Bitmap Data Between Activities in Android with link addresshttps://inabnonapudyawanabing.blogspot.com/2020/06/pass-bitmap-data-between-activities-in.html

0 Response to "Pass Bitmap Data Between Activities in Android"

Post a Comment

Tips Tricks for Android Phone

Tips & Tricks for Android Phone is a free android app and Collection of Tips and Tricks related to using your android mobile device lik...