Android Question Loading an image from a different activity

DoctorGerry

Member
Licensed User
Longtime User
Hi, I have an activity where a user can enter info about an item and then click a button to take a photo of the item. The camera opens in a new activity which allows the user to take the photo, give it a name and save it. How do I then display that photo in the original calling activity?
 

LucaMs

Expert
Licensed User
Longtime User
You could put a routine like this in the "original" activity:
B4X:
Public Sub PhotoIsReady
   ImageView1.Bitmap = LoadBitmap(...)
End sub

and call it from the second Activity using
B4X:
CallSubDelayed(OriginalActivityName, "PhotoIsReady")



You could also pass the folder and name of the image file:
B4X:
Public Sub PhotoIsReady(PhotoDir As String, PhotoName As String)
   ImageView1.Bitmap = LoadBitmap(...)
End sub

B4X:
CallSubDelayed3(OriginalActivityName, "PhotoIsReady", PhotoDir, PhotoName)
 
Upvote 0

RandomCoder

Well-Known Member
Licensed User
Longtime User
The simplest way would be to declare the image as a process global. It can be accessed by all activities, code modules and services.
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
The simplest way would be to declare the image as a process global. It can be accessed by all activities, code modules and services.

It's true, but i don't like it.

I think that using the method I have suggested, the code is more readable and "safe" (ie, no other activity can modify the variable, in this case the image).

[Basically, using this method, you can handle an Activity as though it were a function, almost as an input dialog]
 
Upvote 0
Top