Skip to content

Instantly share code, notes, and snippets.

@nein37
Created August 4, 2014 10:23
Show Gist options
  • Save nein37/fb85b63044e8c749f29e to your computer and use it in GitHub Desktop.
Save nein37/fb85b63044e8c749f29e to your computer and use it in GitHub Desktop.
DialogFragmentのコールバック ref: http://qiita.com/nein37/items/75fcec3ab07f00f6936a
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// 指定したrequestCodeで戻ってくる
if (requestCode == 37)
Log.d("HogeDialogFragmentResult", Integer.toString(requestCode));
}
@Override
public void onClick(DialogInterface dialog, int which) {
Intent result = new Intent();
// 他にパラメータが必要ならこの辺で適当にputExtra
if (getTargetFragment() != null) {
// 呼び出し元がFragmentの場合
getTargetFragment().onActivityResult(getTargetRequestCode(), Activity.RESULT_OK, result);
} else {
// 呼び出し元がActivityの場合
PendingIntent pi = getActivity().createPendingResult(getTargetRequestCode(), result,
PendingIntent.FLAG_ONE_SHOT);
try {
pi.send(Activity.RESULT_OK);
} catch (PendingIntent.CanceledException ex) {
// send failed
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment