• Register
0 votes
20 views

Problem :

I am beginner to Android. I want to transfer a image from one activity to another using Intent. In the first activity a user must select the image from many images from a scroll view and after that a image must be displayed in a imageview of very next activity. How can I achieve this with the help of Intent ?

8 4 2
2,300 points

1 Answer

0 votes

Solution :

I have understood your problem. Please go through below solution on it.

The easiest way to achieve this is with the use of intent.

First you must create the static variable in one of the class as below :

public class MyClass{

public static Bitmap MYPHOTO = null;

}

After that you should get the bitmap from a gallery just to save that bitmap in your MYPHOTO variable.

If you are willing to get the photo from your camera then code is as below.

Intent myintent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(myintent, CAMERA_PIC_REQUEST);

After this you should write below code:

@Override
    public void onActivityResult(int myrequestCode,  int myresultCode, Intent mydata) {
        if (myresultCode == Activity.RESULT_OK) {

            switch (myrequestCode) {
                case CAMERA_PIC_REQUEST:
                    Bitmap myb = (Bitmap) mydata.getExtras().get("mydata");
                    if (myb != null) {
                        MyClass.MYPHOTO = myb;
                    }
                    break;
}
}

Now you can use your MYPHOTO variable in any other Activity.

You can use the same way if you want to pick photo from the gallery.

5 2 1
4,980 points

Related questions

1 vote
1 answer 13 views
13 views
Problem: I want to know : How to pass data from one activity to another in android example . I have basic knowledge in android programming. I have one scenario where just after logging in through my login page then there will be the sign-out button on each of the ... my signed in user to the sign-out. Can someone guide me on how can I keep my session id available to all of the activities?
asked Jul 1 Raphael Pacheco 4.9k points
0 votes
1 answer 4 views