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.
Related
I know this is a very frequently asked questions and there are multiple answers. My question is "which is better?"
I've an activity where I capture an image using camera. I need to pass this image to another activity.
One way is to create Bitmap and pass it in putExtra since Bitmap is a Parcelable. This fails when the image size is too big.
I found 2 solutions. This answer uses MemoryCache to save and retrieve the image. Many answers (this, this and this) recommend to save the image to storage and then pass the path to new activity and read the image there.
Which is a better method in this case? (In terms of speed and memory)
It is safer in any case work with path or link than pass it as it is. It works not only with images but with most types of data. At the same time while working with path you can easy make if/else checks and handling some unexpected scenarios. Also pass the path is much faster.
I am facing a problem with onItemClickListener. I have a ListView which contains strings as well as two images from parse.com table. I want to show the strings and images (that i have pushed in parse.com database) in another activity after I click on any item. I successfully get all the strings using getIntent() but I'm not able to find the solution to fetch the images from ListView item dynamically.
What is the best way to acomplish this?
In this case, the click event can provide the file Url's string value to another activity via the putExtra
look at the docs for calling $FileObj.'getUrl' that retrieves url as Type string
working with images in persistence you should store both full-sz and thumb-sz, working with the thumb in list-adapter context.
So, if u have store the bitmap for the thumbs file on parse, with "getUrl" you can operate on the URL value of the file( its useful in frameworks like 'Volley')
Read up on using adapters particularly "getView" to load the bitmap whenever you need to provide the bmp to a list adapter from your image lib.
Pass the File-Url-string to new activity in "Extra String Value"
Use Volley for your networking/file retreival and bitmap caching. bit of a guess but Volley and parse should be OK.
I am trying to access an image in another activity (say B) which is being captured in activity(say A). Now here, I have two options:
1. Save to sd card and then access in activity B through the filepath.
But, time taken to save is higher in some cases, probably because of higher
image size.
2. Send the bit array through intent.putExtra("imageArray" , data) and access it
in activity B through getIntent(). But on surfing net, I found sending bigger
bitmap of 1MB or more is a bad practise but didn't find anything with regards to
bitarray.
Can someone suggest me which option is better ? And is sending a bitmap of greater size as bitArray to another activity a bad practise ?
My requirement is : time lag between two activities A and B should be minimum. Also, image should be loaded in activity B in no time.
Thanks in advance.
Also you can use global variables in Application space (singleton).
Example:
public class YourApplication extends Application
{
private static YourApplication singleton;
Bitmap bitmap; // or any type, byte array
....
public static YourApplication getInstance()
{
return singleton;
}
}
...
in another class you can set and get this variable 'bitmap':
YourApplication.getInstance().bitmap = ....; // in Activity A
or
... = YourApplication.getInstance().bitmap; // in Activity B
or use inside another method
....( ..., YourApplication.getInstance().bitmap, ...);
If you load the image both in activity A and activity B by using a URL you can use ion - https://github.com/koush/ion. It helps you show pictures using a URL and it caches your image, so that loading it again happens instantly, just send the url from activity A to activity B.
If you use the phone camera to capture a image I would say that saving it is the better way to go, if your gonna want to send many pictures at once in the future the second option will be bad.
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.
i have two activities
1) downloading something on oncreate function with help of asyn task ,and had one button.
2) secons activity display on click of button.
now when i go back to previous ie first activity , then downloading starts again, i want to get the previous filled data view ,instead of startg the previous process again ..
canu please guide me
thanks
You should set a default value to whatever it is you're downloading, for example a default image, text or number, and then before downloading again, check whether the stored value is the default one or something new. If it's new, then you don't have to download again.
For example, in my game I have a similar thing. It's a jigsaw puzzle game with many images, where all the images are displayed in a ListView. To save space, I didn't include both the full size image and a thumbnail, but instead generate the thumbnails when the game loads and saved in a Bitmap[] array. So that bitmap generation process is similar to your downloading.
Whenever my game is about to load a list or access the images, it first checks whether the array is null. If it is, then it restarts the loading process. If it isn't, then it can use them. This is done with a simple check in onResume():
if (imageThumbnails == null) {
// Do something to reload the images
} else {
//the images are available, so they can be used
}
You should be able to do something similar for your app.