how to replace it with ActivityResultLauncher.
sorry guys i am just new to coding and programming.
SelectImageGallery.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select Image From Gallery"), 1);
}
});
2
Answers
You need to register for activity result outside of
onCreate
using belowKotlin
codeNow instead of
startActivityForResult(..)
call below method when you want to open gallery to pick imageINSIDE SAME METHOD AS LISTENER: