Onactivityresult Not Being Trigger From Alert Dialog Fixed
Im adding the ability to upload videos in addition to photos in my app. To accomplish this, now when you click the attach button b2instead of the image chooser loading it loads an
Solution 1:
You need to make sure to set your target fragment for your dialog. to do this add the line before you show the dialog:
newFragment.setTargetFragment(ChatRoomFragment.this, REQUEST_CODE);
within your showDialog method. Doing so will tell your dialog which fragment is supposed to receive the activity's result.
Also, define three constants:
publicstaticfinalint REQUEST_CODE = 0, RESULT_PHOTO = 1, RESULT_VID = 2;
Now, within your Dialog, you should be doing something along the lines of:
...setPositiveButton("Photo",
newDialogInterface.OnClickListener() {
publicvoidonClick(...) {
Intentdata=newIntent();
getTargetFragment().onActivityResult(getTargetRequestCode(), RESULT_PHOTO, data);
}})
.setNegativeButton(...
getTargetFragment().onActivityResult(getTargetRequestCode(), RESULT_VID, data); ...
Then in your onActivityResult method, you need to do a check for the request code and result code pairs:
if(requestCode == REQUEST_CODE && resultCode == RESULT_PHOTO) { doPositiveClick(); } ...
Post a Comment for "Onactivityresult Not Being Trigger From Alert Dialog Fixed"