title: How to pass retrofit data in bundle to view pager fragments from activity?
body: <p>In my activity i am receiving a game id from previous activity and using this id i am getting list of data from api. The method ("ApiCheats") in activity is used to get lis t of data.</p>
  
  <p>I want to pass this list to my fragment in view pager, for this i used bundle but in fragment the bundle is null.</p>
  
  <p>How should i pass bundle list to fragment , this data i am receiving through retrofit.</p>
  
  <p>This is the Activity</p>
  
  <pre><code> public class GameListCheatsActivity extends AppCompatActivity {
  
      private final String TAG = GameListCheatsActivity.class.getSimpleName();
      public List&lt;Cheats&gt; Cheats;
      ArrayList cheats = new ArrayList&lt;Cheats&gt;();
   //   public RecyclerView recyclerView;
      String Gameid;
      ViewPager viewPager;
      ViewPagerAdapter adapter;
      TabLayout tabLayout ;
  
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_game_list_cheats);
  //        recyclerView = (RecyclerView) findViewById(R.id.recycler_id);
  //        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
  //        recyclerView.setLayoutManager(linearLayoutManager);
  //        recyclerView.setHasFixedSize(true);
  
  
          Gameid = getIntent().getStringExtra("GameID");
          tabLayout = (TabLayout) findViewById(R.id.tab_layout_id);
          viewPager = (ViewPager) findViewById(R.id.viewpager_id);
          adapter = new ViewPagerAdapter( getSupportFragmentManager());
          ApiCheats();
          adapter.AddFragment(new Fragment_Cheats(),"GameCheats");
          adapter.AddFragment(new Fragment_Favourites(),"Favourites");
          viewPager.setAdapter(adapter);
          tabLayout.setupWithViewPager(viewPager);
  
  
  
  
          viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
              @Override
              public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
  
              }
  
              @Override
              public void onPageSelected(int position) {
  
              }
  
              @Override
              public void onPageScrollStateChanged(int state) {
                  if(state == 0){
                      View inflatedView = getLayoutInflater().inflate(R.layout.cheatitem, null);
  
  
  
  
                  }
                  if(state == 1){
                      View inflatedView = getLayoutInflater().inflate(R.layout.cheatitem, null);
  
                  }
  
              }
          });
  
  
  
  
      }
  
      public void ApiCheats()
      {
          ApiUtil.getServiceClass().getAllCheats(Gameid).enqueue(new Callback&lt;List&lt;Cheats&gt;&gt;() {
              @Override
              public void onResponse(Call&lt;List&lt;Cheats&gt;&gt; call, Response&lt;List&lt;Cheats&gt;&gt; response) {
                  if(response != null)
                  {
                      if(response.isSuccessful())
                      {
                        Cheats =  response.body();
  
                          Bundle bundle = new Bundle();
                          bundle.putParcelableArrayList("cheatslist", (ArrayList&lt;? extends Parcelable&gt;) Cheats);
                          Fragment_Cheats fragment_cheats = new Fragment_Cheats();
                          fragment_cheats.setArguments(bundle);
  
  
  
                      }
  
                  }
                  Log.d(TAG, "Returned count " + Cheats.size());
  
                  GameListCheatsActivity.this.runOnUiThread(new Runnable() {
                      @Override
                      public void run() {
                        //  CheatsAdapter adapter = new CheatsAdapter(getApplicationContext(), Cheats);
                        //  recyclerView.setAdapter(adapter);
  
  
                      }
                  });
  
              }
  
              @Override
              public void onFailure(Call&lt;List&lt;Cheats&gt;&gt; call, Throwable t) {
                  Log.d(TAG, "error loading from API");
              }
          });
  
      }
  
  
  
  }
  </code></pre>
  
  <p>this is one of the fragments class</p>
  
  <pre><code>public class Fragment_Cheats extends Fragment   {
  
  
      View v;
      private RecyclerView mrecyclerview;
      private List&lt;Cheats&gt; lstGameCheats;
  
  
      public Fragment_Cheats()
      {
  
      }
  
  
  //    @Override
  //    public void onCreate(@Nullable Bundle savedInstanceState) {
  //        super.onCreate(savedInstanceState);
  //
  //        Bundle bundle = this.getArguments();
  //        if (bundle != null) {
  //            lstGameCheats = bundle.getParcelable("cheatslist");
  //        }
  //
  //    }
  
  
  
  
      @Override
      public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
          v = inflater.inflate(R.layout.fragment_fragment__cheats, container, false);
          mrecyclerview = (RecyclerView)v.findViewById(R.id.recyclerview_cheats);
  
          Bundle bundle = this.getArguments();
          if (bundle != null) {
              lstGameCheats = bundle.getParcelable("cheatslist");
          }
          CheatsAdapter recyclerAdapter = new CheatsAdapter(getContext(),lstGameCheats);
          mrecyclerview.setLayoutManager(new LinearLayoutManager(getActivity()));
          mrecyclerview.setAdapter(recyclerAdapter);
          return  v;
  
      }
  
  }
  </code></pre>
  
  <p>this is view pager adapter</p>
  
  <pre><code>    public class ViewPagerAdapter extends FragmentPagerAdapter {
  
      private final List&lt;Fragment&gt; lstFragment = new ArrayList&lt;&gt;();
      private final List&lt;String&gt; lstTitles = new ArrayList&lt;&gt;();
  
  
      public ViewPagerAdapter(FragmentManager fm) {
          super(fm);
      }
  
      @Override
      public Fragment getItem(int position) {
          return lstFragment.get(position);
          //return null;
      }
  
      @Override
      public int getCount() {
          return lstTitles.size();
          //return 0;
      }
  
      @Nullable
      @Override
      public CharSequence getPageTitle(int position) {
          return lstTitles.get(position);
      }
  
  
      public  void AddFragment(Fragment fragment,String title){
  
          lstFragment.add(fragment);
          lstTitles.add(title);
      }
  
  
  }
  </code></pre>