title: How to read object which is used by a fragment
body: <p>First of all, I hope my question is clear. If it isn't please comment i will try to make it better!.</p>
  
  <p>i have a question related to putting a item in a arraylist. I am using the master/detail flow (a standard project option in android studio) as a bases for my app. I already modified it but below is de code from the original template to simplify my question. For my problem i think there are three activities involved. Main activity, detail activity, mysavedbooks and the fragment activity. </p>
  
  <p>My Problem
  In the detail activity there is a fab button. WHat i want to do is to save the current displayed item in a new arraylist called Saveditems in the activity mysavedbooks.</p>
  
  <p>How can i read the item  (which is currently displayed by the detailactivity which extends the fragment) and put this in a saveditems arraylist. </p>
  
  <p>Greetings,
  Matthijs</p>
  
  <p>below is the main activity </p>
  
  <pre><code>import android.content.Context;
  import android.content.Intent;
  import android.os.Bundle;
  import android.support.annotation.NonNull;
  import android.support.v7.app.AppCompatActivity;
  import android.support.v7.widget.LinearLayoutManager;
  import android.support.v7.widget.RecyclerView;
  import android.support.v7.widget.Toolbar;
  import android.support.design.widget.FloatingActionButton;
  import android.support.design.widget.Snackbar;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.TextView;
  
  
  import matthijs.bookshelf.dummy.DummyContent;
  
  import java.util.List;
  
  /**
   * An activity representing a list of books. This activity
   * has different presentations for handset and tablet-size devices. On
   * handsets, the activity presents a list of items, which when touched,
   * lead to a {@link bookDetailActivity} representing
   * item details. On tablets, the activity presents the list of items and
   * item details side-by-side using two vertical panes.
   */
  public class bookListActivity extends AppCompatActivity {
  
  /**
   * Whether or not the activity is in two-pane mode, i.e. running on a tablet
   * device.
   */
  private boolean mTwoPane;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_book_list);
  
      Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
      setSupportActionBar(toolbar);
      toolbar.setTitle(getTitle());
  
      FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
      fab.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View view) {
              Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                      .setAction("Action", null).show();
          }
      });
  
      View recyclerView = findViewById(R.id.book_list);
      assert recyclerView != null;
      setupRecyclerView((RecyclerView) recyclerView);
  
      if (findViewById(R.id.book_detail_container) != null) {
          // The detail container view will be present only in the
          // large-screen layouts (res/values-w900dp).
          // If this view is present, then the
          // activity should be in two-pane mode.
          mTwoPane = true;
      }
  }
  
  private void setupRecyclerView(@NonNull RecyclerView recyclerView) {
      recyclerView.setAdapter(new SimpleItemRecyclerViewAdapter(DummyContent.ITEMS));
  }
  
  public class SimpleItemRecyclerViewAdapter
          extends RecyclerView.Adapter&lt;SimpleItemRecyclerViewAdapter.ViewHolder&gt; {
  
      private final List&lt;DummyContent.DummyItem&gt; mValues;
  
      public SimpleItemRecyclerViewAdapter(List&lt;DummyContent.DummyItem&gt; items) {
          mValues = items;
      }
  
      @Override
      public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
          View view = LayoutInflater.from(parent.getContext())
                  .inflate(R.layout.book_list_content, parent, false);
          return new ViewHolder(view);
      }
  
      @Override
      public void onBindViewHolder(final ViewHolder holder, int position) {
          holder.mItem = mValues.get(position);
          holder.mIdView.setText(mValues.get(position).id);
          holder.mContentView.setText(mValues.get(position).content);
  
          holder.mView.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  if (mTwoPane) {
                      Bundle arguments = new Bundle();
                      arguments.putString(bookDetailFragment.ARG_ITEM_ID, holder.mItem.id);
                      bookDetailFragment fragment = new bookDetailFragment();
                      fragment.setArguments(arguments);
                      getSupportFragmentManager().beginTransaction()
                              .replace(R.id.book_detail_container, fragment)
                              .commit();
                  } else {
                      Context context = v.getContext();
                      Intent intent = new Intent(context, bookDetailActivity.class);
                      intent.putExtra(bookDetailFragment.ARG_ITEM_ID, holder.mItem.id);
  
                      context.startActivity(intent);
                  }
              }
          });
      }
  
      @Override
      public int getItemCount() {
          return mValues.size();
      }
  
      public class ViewHolder extends RecyclerView.ViewHolder {
          public final View mView;
          public final TextView mIdView;
          public final TextView mContentView;
          public DummyContent.DummyItem mItem;
  
          public ViewHolder(View view) {
              super(view);
              mView = view;
              mIdView = (TextView) view.findViewById(R.id.id);
              mContentView = (TextView) view.findViewById(R.id.content);
          }
  
          @Override
          public String toString() {
              return super.toString() + " '" + mContentView.getText() + "'";
          }
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>below is the detail activity. </p>
  
  <pre><code>import android.content.Intent;
  import android.os.Bundle;
  import android.support.design.widget.FloatingActionButton;
  import android.support.design.widget.Snackbar;
  import android.support.v7.widget.Toolbar;
  import android.view.View;
  import android.support.v7.app.AppCompatActivity;
  import android.support.v7.app.ActionBar;
  import android.support.v4.app.NavUtils;
  import android.view.MenuItem;
  
  /**
   * An activity representing a single book detail screen. This
   * activity is only used narrow width devices. On tablet-size devices,
   * item details are presented side-by-side with a list of items
   * in a {@link bookListActivity}.
   */
  public class bookDetailActivity extends AppCompatActivity {
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_book_detail);
      Toolbar toolbar = (Toolbar) findViewById(R.id.detail_toolbar);
      setSupportActionBar(toolbar);
  
      FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
      fab.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View view) {
              Snackbar.make(view, "saved book", Snackbar.LENGTH_LONG)
                      .setAction("Action", null).show();
  
  
  
          }
      });
  
      // Show the Up button in the action bar.
      ActionBar actionBar = getSupportActionBar();
      if (actionBar != null) {
          actionBar.setDisplayHomeAsUpEnabled(true);
      }
  
      // savedInstanceState is non-null when there is fragment state
      // saved from previous configurations of this activity
      // (e.g. when rotating the screen from portrait to landscape).
      // In this case, the fragment will automatically be re-added
      // to its container so we don't need to manually add it.
      // For more information, see the Fragments API guide at:
      //
      // http://developer.android.com/guide/components/fragments.html
      //
      if (savedInstanceState == null) {
          // Create the detail fragment and add it to the activity
          // using a fragment transaction.
          Bundle arguments = new Bundle();
          arguments.putString(bookDetailFragment.ARG_ITEM_ID,
                  getIntent().getStringExtra(bookDetailFragment.ARG_ITEM_ID));
          bookDetailFragment fragment = new bookDetailFragment();
          fragment.setArguments(arguments);
          getSupportFragmentManager().beginTransaction()
                  .add(R.id.book_detail_container, fragment)
                  .commit();
      }
  }
  
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
      int id = item.getItemId();
      if (id == android.R.id.home) {
          // This ID represents the Home or Up button. In the case of this
          // activity, the Up button is shown. Use NavUtils to allow users
          // to navigate up one level in the application structure. For
          // more details, see the Navigation pattern on Android Design:
          //
          // http://developer.android.com/design/patterns/navigation.html#up-vs-back
          //
          NavUtils.navigateUpTo(this, new Intent(this, bookListActivity.class));
          return true;
      }
      return super.onOptionsItemSelected(item);
  }
  }
  </code></pre>
  
  <p>below is the fragment </p>
  
  <pre><code>package matthijs.bookshelf;
  
  import android.app.Activity;
  import android.support.design.widget.CollapsingToolbarLayout;
  import android.os.Bundle;
  import android.support.v4.app.Fragment;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.TextView;
  
  import matthijs.bookshelf.dummy.DummyContent;
  
  /**
   * A fragment representing a single book detail screen.
   * This fragment is either contained in a {@link bookListActivity}
   * in two-pane mode (on tablets) or a {@link bookDetailActivity}
   * on handsets.
   */
  public class bookDetailFragment extends Fragment {
      /**
       * The fragment argument representing the item ID that this fragment
       * represents.
       */
      public static final String ARG_ITEM_ID = "item_id";
  
      /**
       * The dummy content this fragment is presenting.
       */
      private DummyContent.DummyItem mItem;
  
      /**
       * Mandatory empty constructor for the fragment manager to instantiate the
       * fragment (e.g. upon screen orientation changes).
       */
      public bookDetailFragment() {
      }
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
  
      if (getArguments().containsKey(ARG_ITEM_ID)) {
          // Load the dummy content specified by the fragment
          // arguments. In a real-world scenario, use a Loader
          // to load content from a content provider.
          mItem = DummyContent.ITEM_MAP.get(getArguments().getString(ARG_ITEM_ID));
  
          Activity activity = this.getActivity();
          CollapsingToolbarLayout appBarLayout = (CollapsingToolbarLayout) activity.findViewById(R.id.toolbar_layout);
          if (appBarLayout != null) {
              appBarLayout.setTitle(mItem.content);
          }
      }
  }
  
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
                           Bundle savedInstanceState) {
      View rootView = inflater.inflate(R.layout.book_detail, container, false);
  
      // Show the dummy content as text in a TextView.
      if (mItem != null) {
          ((TextView) rootView.findViewById(R.id.book_detail)).setText(mItem.details);
      }
  
      return rootView;
  }
  }
  </code></pre>
  
  <p>Mysavedbooks activity </p>
  
  <pre><code>package matthijs.tuinierv2;
  
          import java.util.ArrayList;
          import java.util.List;
  
  /**
   * Created by Matthijs on 12-2-2016.
   */
  public class Mysavedbooks {
  
      public static final List&lt;DummyContent.DummyItem&gt; SavedItems= new   ArrayList&lt;DummyContent.DummyItem&gt;();
  
  }
  </code></pre>