0
//Example of ImageButton in the old way how it was handled

img_btn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
            photoPickerIntent.setType("image/*");
            startActivityForResult(photoPickerIntent, 500);

        }
    });

With onactivityresult for example like:

public void onActivityResult(int requestCode, int resultCode, Intent data) {
         super.onActivityResult(requestCode, resultCode, data);

         switch(requestCode) {
                  case 500:
                       if(resultCode == RESULT_OK){
                                   try {
                                      final Uri imageUri = data.getData();
                                      final InputStream imageStream =  getActivity().getContentResolver().openInputStream(imageUri);
                        final Bitmap selectedImage = BitmapFactory.decodeStream(imageStream);
                        imageButton.setImageBitmap(selectedImage);
                         } catch (FileNotFoundException e) {
                                e.printStackTrace();
                         }

                        }


}

}

I'm using jdk 1.8 and android 6.0, How can i change it using an alternative that is not deprecated?

  • 5
    Does this answer your question? [OnActivityResult method is deprecated, what is the alternative?](https://stackoverflow.com/questions/62671106/onactivityresult-method-is-deprecated-what-is-the-alternative) – javdromero Jul 02 '21 at 18:35
  • I've already analyzed that post, but unfortunately doesn't answer my question – Valerio Jiang Jul 03 '21 at 16:58

0 Answers0