SupportLibrary 23.2+ で Fragment で受けれる startActivityForResult()

android_support_library_-_Google_Search_🔊

Android Support Library 23.2 | Android Developers Blog

「これは大きい機能の更新」ということですが.

// SecondFragment.java
 
// Calling to SecondActivity
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
  ...
  btnGo = (Button) rootView.findViewById(R.id.btnGo);
  btnGo.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
      Intent intent = new Intent(getContext(), SecondActivity.class);
      startActivityForResult(intent, 12345);
    }
  });
}
 
// Get Result Back
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
  super.onActivityResult(requestCode, resultCode, data);
  Log.d("onActivityResult", "requestCode = " + requestCode);
}

onActivityResult() inside Nested Fragment is now called on Support Library rev 23.2 and above :: The Cheese Factory

23.2 よりも前の場合は EventBus を使って, 元の Activity で受ける方法しかなかったが, 置き換えした Fragment で受けれるということなのだろうが.

dependencies {
  compile 'com.squareup:otto:1.3.6'
}

How to make onActivityResult get called on Nested Fragment :: The Cheese Factory

でも, 逆にもう

「EventBus で戻す」だけ

でもいいように思えてきましたが, 手抜きすぎるか.

Otto自体はメンテ終了しているので, Rx方面に進むのがよいのだろうか.

OttoからRxJavaへの移行ガイド - Qiita

元記事「nest」という言葉が気にはなるが.

サポートライブラリ群のバージョン表記もなんとなく紛らわしくなってきたな, と.

032: Making sense of Android Support Library version numbers – Fragmented