How to send image from one activity to another in android?

前端 未结 8 1871
忘掉有多难
忘掉有多难 2020-12-10 08:18

I am having a imageView in one class and on clicking the imageView a dialog box appear which has two option to take a image from camera or open the image gallery of device.

8条回答
  •  北海茫月
    2020-12-10 08:43

    My preferred way (and I think the most straight-forward way) is to use an own Application instance in the app, to store variables that are common to more than 1 activity.

    Create a class, let's call it MainApplication that extends android.app.Application and declare it in the manifest:

    
    

    Then you get an instance of the application object in the Activity like this:

    MainApplication application = ((MainApplication)getApplication());
    

    Inside this application object you can store any app-level data and use it as usual:

    application.setImage(...);
    
    application.getImage();
    

提交回复
热议问题