title: Custom RecyclerAdapter and startActivityForResult
body: <p>I have a <code>Fragment</code> that contains a <code>RecyclerView</code> which uses a custom <code>RecyclerAdapter</code>. I have an <code>onClickListener</code> inside my custom <code>RecyclerAdapter</code> - when a position is clicked I want it to start <code>startActivityForResult</code>.  So far this works in as such as when it is clicked it starts the Activity as desired. However when I press the back button to go to the <code>Fragment</code> containing the <code>RecyclerView</code> <code>onActivityResult</code> is never called.  I have passed in a context to the custom <code>RecyclerAdapter</code>.  Is this something that is possible? Or does the Activity/Fragment initiating <code>startActivityForResult</code> be the one that intercepts it? If not I will end up handling the onClick in the Fragment with a gesture detector or something similar, but before that I wanted to give this a fair crack! Note: I have included <code>onActivityResult</code> in the <code>MainActivity</code> which has the <code>Fragment</code> container so the <code>Fragment</code> does receive <code>onActivityResult</code> if <code>startActivityForResult</code> is initiated from the <code>Fragment</code>.  My code:</p>
  
  <p>RecyclerAdapter onClickListener:</p>
  
  <pre><code>@Override
          public void onClick(View v) {
  
              String titleId = titlesListDataArrayList.get(getLayoutPosition()).getTitle_id();
  
              Intent intent = new Intent(context, CreateItemsActivity.class);
              intent.putExtra("TITLE_ID", titleId);
              ((Activity) context).startActivityForResult(intent, Constants.NEW_ITEMS_REQUEST_CODE);
          }
  </code></pre>
  
  <p>CreateItemsActivity.class - onBackPressed()</p>
  
  <pre><code>    @Override
          public void onBackPressed() {
  
              Intent intent = new Intent();
              setResult(Constants.NEW_ITEMS_REQUEST_CODE, intent);
              finish();
          }
  </code></pre>
  
  <p>MyListsFragment.class (contains RecyclerView)</p>
  
  <pre><code>@Override
      public void onActivityResult(int requestCode, int resultCode, Intent data) {
          super.onActivityResult(requestCode, resultCode, data);
  
          Log.e("CALLED", "OnActivity Result");
  
          // if requestCode matches from CreateItemsActivity
          if (requestCode == Constants.NEW_ITEMS_REQUEST_CODE) {
  
              Log.e("REQUEST CODE", String.valueOf(requestCode));
  
              populateRecyclerView();
          }
      }
  </code></pre>
  
  <p>Also I have this in the MainActivity:</p>
  
  <pre><code>@Override
      protected void onActivityResult(int requestCode, int resultCode, Intent data) {
          super.onActivityResult(requestCode, resultCode, data);
          // included to allow fragment to receive onActivityResult
  
      }
  </code></pre>