Retrieve Image from another Intent - android

How can I retrieve an image from another Intent within the same application?

If I understood you correctly you can use Intent.putExtra(String, Parcelable) and Intent.getParcelableExtra(String) methods to store and load image. But it's not very fast method. And if you need to transfer a large image, you'd better put it in a static field.

Related

Creating Android PDF file using two two Activities

I have two Activities, Activity_1 and Activity_2.
In Activity_1, I have an ImageView and a Button called "Go to Next".
In Activity_2, I have a Button called "CreatePDF".
So, I just want to know how to create a PDF with an image from Activity_1 when I press the CreatePDF button in Activity_2.
I would thankful if any one can solve this.
Thank You
From the few details you are giving here, I assume the Activity_2 does not know the image you want to export.
So first, you need to pass a reference to the image, or the image data itself, from Activity_1 to Activity_2.
See this post which may have what you're looking for.
The accepted answer is suggesting to use one of these three solutions:
Convert the image from Bitmap to byte array, then pass this byte array from one activity to another using an Intent object.
Save the image to the SD Card (or anywhere on the phone) and pass the image file path as a string from one activity to another, using an Intent object.
Pass the Bitmap image using an Intent object, without converting it.
I hope this helps.

How to send a Bitmap to another activity without saving it?

In Activity A, I download an image using Picasso and save into a Bitmap. I need that Bitmap in Activity B, how can I send it in the bundle without saving the image into the file system, and without sending the bitmap, as it's not very efficient?
EDIT: Is it possible to use the resource ID? If so, how?
If you strictly don't want to pass Bitmap to Bundle, you can extend Application class, and store/get bitmap to/from it. However, I'm asking you not to do this, and consider to send Bitmaps through Bundles, because storing such data in Application class is much worse then overhead from sending or storing in file system.
Bitmap implements Parcelable interface. So, you can pass it via bundle.
For sending,
Intent intent = new Intent(CallingActivity.this, CalledActivity.class);
intent.putExtra("bitmap", bitmap);
startActivity(intent);
To retrieve it,
Bitmap bitMap = getIntent().getParcelableExtra("bitmap");

Intent bundle size

I need to send an intent where data might be large. Since it's not possible to send intent larger than 500kb, I'd like to know the size, but there isn't any sizeof in java, how can I check the size before to send or to reduce the size?
Rather than sending data using intent declare another class "Data" to store values with static variables and use them whenever you want.

How to pass large json string to next activity

I am sending large JSON string where records of JSON array length is 800 but currently when I start that Activity then application quits without any crash message but when I reduced the records to 100 then it works perfectly.
I am doing like below
Intent myIntent = new Intent(getActivity(),
ActivityName.class);
myIntent.putExtra("jsondata", respUserData);
getParentFragment().startActivityForResult(myIntent,
pick_plan);
getActivity().overridePendingTransition(
R.anim.lefttorightanim, R.anim.righttoleftanim);
So what it is correct way to send large JSON to next Activity ?
Thanks in advance.
Don't pass large String or Large Data directly in to intent, you have to use Application Class.
Set variables and methods in application class.
To get more information about Application Class view this answer.
Since it's probably not a global state that you pass, I advise against using the Application Class. If it is data that you use all the time you can easily store it there.
For passing a large amount of data using the provided way with putExtra() should work fine. Apparently the Bundle doesn't handle your JSONObject correctly. You can try to convert it to a String, pass this to the Intent.putExtra() and then reconstruct the JSONObject from the String. This will have some impact on the performance, but should be usable as a workaround.
You can pass values as you mentioned. It will be as a bundle so it can hold large amount of data also.
We can pass Arraylist, model classes etc using the intent.

How to send an object containing drawable objects from one android activity to another using intents?

I've gone through this: How to send an object from one Android Activity to another using Intents?
But i'm facing problem in sending images in the object to the other activity.
Please help.
Convert your Drawable to Bitmap and send it to Another Activity.
Bitmap bitmap = ((BitmapDrawable)d).getBitmap();
To send,
intent.putExtra("Bitmap", bitmap);
To Fetch,
Bitmap bitmap = (Bitmap)this.getIntent().getParcelableExtra("Bitmap");
Well you can't really send images with intents since you can attach as extras to intents only Serializable objects.
But you can store images (in memory in different structures (like HashMaps, using hashmap will give you some speed optimization for searching that image)) and send notification to other activity to read from hasmap. You can add the key for the image in hashmap as string in extras attached to intent.
Or you can just cache the image and send it's name/path via intents :)
Hope this helps :)

Categories

Resources