title: How do I use onResume and onPause method when I am pressed back button
body: <p>I have a custom adapter for recyclerview using json webservices. I had to parse the url one by one and show cardview using onscrolllistener(). My question is when I pressed the back button and after I open in recent app (that time onResume called) it will show only which url called at the time of onPause called. So how can I refresh the listview when I call onResume.</p>
  
  <pre><code>Thanks in Advance,
  
  Here my code synepet..
  
  public class MainActivity extends AppCompatActivity {
  
      private RecyclerView mRecyclerView;
      private RecyclerView.Adapter mAdapter;
      private GridLayoutManager mGridManager;
      private ProgressBar mProgressBar;
  
      private static String url = "https://www.googleapis.com/youtube/v3/playlists?part=snippet&amp;channelId=UCGyZswzm4G-wEfRQHgMSAuw&amp;maxResults=50&amp;key=AIzaSyCi0ApXYk08YpzyEO8jYJanaud-Epti6ks&amp;pageToken=CDIQAQ";
  
      JSONArray contacts = null;
      private String mNextToken;
      JSONObject jsonObj;
      private boolean loading = true;
      int visibleItemCount, totalItemCount, pastVisiblesItems;
      private List&lt;PlayListItem&gt; mContactList = new ArrayList&lt;PlayListItem&gt;();
      private PlayListItem mContact;
      private Bundle mbundle;
      String name2 = "Arasu";
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
          setSupportActionBar(toolbar);
  
          mProgressBar = (ProgressBar) findViewById(R.id.progressBar);
          mRecyclerView = (RecyclerView) findViewById(R.id.recycler_view);
          mRecyclerView.setHasFixedSize(true);
  
          // Calling async task to get json
          new GetContacts().execute();
  
          mAdapter = new CardAdapter(MainActivity.this, mContactList);
          mRecyclerView.setAdapter(mAdapter);
          getScreenOrientation();
      }
  
      @Override
      public void onResume() {
          super.onResume();
      }
  
      @Override
      protected void onPause() {
          super.onPause();
          System.out.println("Size2----&gt;" + mContactList.size());
      }
  
  
  private class GetContacts extends AsyncTask&lt;Void, Void, Void&gt; {
  
          @Override
          protected void onPreExecute() {
              super.onPreExecute();
              // Showing progress dialog
              mProgressBar.setVisibility(View.VISIBLE);
              mProgressBar.setMax(100);
          }
  
          @Override
          protected Void doInBackground(Void... arg0) {
              // Creating service handler class instance
              ServiceHandler sh = new ServiceHandler();
  
              // Making a request to url and getting response
              String jsonArray = sh.makeServiceCall(url, ServiceHandler.GET);
  
              //Log.d("Response: ", "&gt; " + jsonArray);
              if (jsonArray != null) {
                  try {
                      jsonObj = new JSONObject(jsonArray);
  
                      if (jsonObj.has("nextPageToken")) {
                          loading = true;
                          mNextToken = jsonObj.getString("nextPageToken");
                      } else {
                          loading = false;
                      }
                      // Getting JSON Array node
                      contacts = jsonObj.getJSONArray("items");
  
                      // looping through All Contacts
                      for (int i = 0; i &lt; contacts.length(); i++) {
                          JSONObject c = contacts.getJSONObject(i);
                          String title = c.getJSONObject("snippet").getString("title");
                          String time = c.getJSONObject("snippet").getString("publishedAt");
                          String playlist_id = c.get("id").toString();
  
                          // Find Screen size and set the Image for this size
                          DisplayMetrics dm = new DisplayMetrics();
                          getWindowManager().getDefaultDisplay().getMetrics(dm);
                          double x = Math.pow(dm.widthPixels / dm.xdpi, 2);
                          double y = Math.pow(dm.heightPixels / dm.ydpi, 2);
                          double screenInches = Math.sqrt(x + y);
                          int inch = (int) Math.round(screenInches);
                          String image = null;
  
                          try {
                              if (inch &lt;= 4) {
                                  image = c.getJSONObject("snippet").getJSONObject("thumbnails").getJSONObject("medium").getString("url");
                              } else if (inch &gt; 4 &amp;&amp; inch &lt;= 6) {
                                  image = c.getJSONObject("snippet").getJSONObject("thumbnails").getJSONObject("medium").getString("url");
                              } else if (inch &gt; 6 &amp;&amp; inch &lt;= 10) {
                                  image = c.getJSONObject("snippet").getJSONObject("thumbnails").getJSONObject("medium").getString("url");
                              } else {
                                  image = c.getJSONObject("snippet").getJSONObject("thumbnails").getJSONObject("default").getString("url");
                              }
                          } catch (IndexOutOfBoundsException e) {
                              e.printStackTrace();
                          }
  
                          mContact = new PlayListItem();
                          mContact.setmTitle(title);
                          mContact.setmID(playlist_id);
                          mContact.setmTime(time);
                          mContact.setmThumbnailURL(image);
                          mContact.setmNextToken(mNextToken);
                          mContactList.add(mContact);
                      }
                  } catch (JSONException e) {
                      e.printStackTrace();
                  }
              } else {
                  Log.e("ServiceHandler", "Couldn't get any data from the url");
              }
              return null;
          }
  
          @Override
          protected void onPostExecute(Void result) {
              super.onPostExecute(result);
              // Dismiss the progress dialog
              if (mProgressBar.isShown())
                  mProgressBar.setVisibility(ProgressBar.GONE);
              mAdapter.notifyDataSetChanged();
  
              mRecyclerView.setOnScrollListener(new RecyclerView.OnScrollListener() {
  
                  @Override
                  public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
                      super.onScrolled(recyclerView, dx, dy);
                      visibleItemCount = mGridManager.getChildCount();
                      totalItemCount = mGridManager.getItemCount();
                      pastVisiblesItems = mGridManager.findFirstVisibleItemPosition();
  
                      if (loading) {
                          if ((visibleItemCount + pastVisiblesItems) &gt;= totalItemCount) {
  
                              Log.v("...", "Last Item Wow !");
                              if (jsonObj.has("nextPageToken")) {
                                  url = "https://www.googleapis.com/youtube/v3/playlists?part=snippet&amp;channelId=UCGyZswzm4G-wEfRQHgMSAuw&amp;maxResults=50&amp;key=AIzaSyCi0ApXYk08YpzyEO8jYJanaud-Epti6ks&amp;pageToken=" + mNextToken;
                                  System.out.println("url---&gt;" + url);
                                  new GetContacts().execute();
                              } else {
                                  url = "https://www.googleapis.com/youtube/v3/playlists?part=snippet&amp;channelId=UCGyZswzm4G-wEfRQHgMSAuw&amp;maxResults=50&amp;key=AIzaSyCi0ApXYk08YpzyEO8jYJanaud-Epti6ks&amp;pageToken=" + mNextToken;
                                  System.out.println("url----else---&gt;" + url);
                                  new GetContacts().execute();
                              }
                              loading = false;
                          }
                      }
                  }
              });
          }
      }
  }
  
  public class CardAdapter extends RecyclerView.Adapter&lt;CardAdapter.ViewHolder&gt; {
      private List&lt;PlayListItem&gt; mItems;
      private Activity activity;
      public ImageLoader imageLoader;
      public CardAdapter(Activity activity, List&lt;PlayListItem&gt; items) {
          this.activity = activity;
          this.mItems = items;
          imageLoader = new ImageLoader(activity.getApplicationContext());
      }
  
      @Override
      public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
          View v = LayoutInflater.from(viewGroup.getContext())
                  .inflate(R.layout.recycler_outer_playlist_cardview, viewGroup, false);
          ViewHolder viewHolder = new ViewHolder(v);
          return viewHolder;
      }
  
      @Override
      public void onBindViewHolder(ViewHolder viewHolder, final int i) {
          System.out.println("Title Value is-----------&gt;"+mItems.get(0));
          PlayListItem nature = mItems.get(i);
  
          Log.d("Title Value is","-----------&gt;"+nature.getmTitle());
          viewHolder.tvTitle.setText(nature.getmTitle());
  
          final String playListID = nature.getmID();
          final String thumnailsURL = nature.getmThumbnailURL();
  
          final Calendar c = Calendar.getInstance();
          int cur_year = c.get(Calendar.YEAR);
          int cur_month = c.get(Calendar.MONTH) + 1;
          int cur_day = c.get(Calendar.DAY_OF_MONTH);
          int cur_hour = c.get(Calendar.HOUR_OF_DAY);
          int cur_minute = c.get(Calendar.MINUTE);
  
          // Getting updated date from url
          String string = nature.getmTime();
          String[] parts = string.split("-");
          String part1 = parts[0]; // 004
          String part2 = parts[1]; // 034556
          String part3 = parts[2];
          String[] part4 = part3.split("T");
          String part5 = part4[0];
          String part6 = part4[1];
          // Toast.makeText(activity, "Given Date is : " + part1 + "/" + part2 + "/" + part3, Toast.LENGTH_LONG).show();
  
          // Log.d("Updated Current Day", part5);
          int giv_yr = Integer.parseInt(part1);
          int giv_mnt = Integer.parseInt(part2);
          int giv_day = Integer.parseInt(part5);
  
          // Difference Two dates
          int day_yr = 0, day_mnt = 0, day_day = 0;
  
          if (cur_year &gt;= giv_yr) {
              if (cur_year &gt;= giv_yr) {
                  day_yr = cur_year - giv_yr;
              } else {
                  day_yr = giv_yr - cur_year;
              }
              if (cur_month &gt;= giv_mnt) {
                  day_mnt = cur_month - giv_mnt;
              } else {
                  day_mnt = giv_mnt - cur_month;
              }
              if (cur_day &gt;= giv_day) {
                  day_day = cur_day - giv_day;
              } else {
                  day_day = giv_day - cur_day;
              }
          }
          String yr = Integer.toString(day_yr);
          String mnt = Integer.toString(day_mnt);
          String days = Integer.toString(day_day);
  
          if (day_day == 0)
              viewHolder.tvTime.setText("Updated Today");
          else if (day_day &lt; 7)
              viewHolder.tvTime.setText("Updated " + days + " Days ago");
          else if (day_day &lt; 30) {
              int week = day_day / 7;
              String Week = Integer.toString(week);
              viewHolder.tvTime.setText("Updated " + Week + " Weeks ago");
          } else {
              viewHolder.tvTime.setText("Updated " + mnt + " Months ago");
          }
  
          //imageLoader.DisplayImage(nature.getmThumbnailURL(), viewHolder.imgThumbnail);
          Picasso.with(activity)
                  .load(nature.getmThumbnailURL())
                  /*.placeholder(R.drawable.my_thumnail)*/
                 .into(viewHolder.imgThumbnail);
  
          viewHolder.item_view.setOnClickListener(new OnClickListener() {
              @Override
              public void onClick(View v) {
                  Intent intent = new Intent(activity, VideoPlayActivity.class);
                  intent.putExtra("PLAYLIST_ID", playListID);
                  intent.putExtra("THUMNAIL_URL", thumnailsURL);
                  v.getContext().startActivity(intent);
              }
          });
          /*System.out.println("URL --------------&gt;"+nature.getmThumbnailURL());
          // String img_url = nature.getmThumbnailURL();
          try {
              URL url = new URL(nature.getmThumbnailURL());
              Bitmap bmp = BitmapFactory.decodeStream(url.openConnection().getInputStream());
              System.out.println("Image bmp --------------&gt;"+bmp);
              //imageView.setImageBitmap(bmp);
              viewHolder.imgThumbnail.setImageBitmap(bmp);
          } catch (MalformedURLException e) {
              e.printStackTrace();
          } catch (IOException e) {
              e.printStackTrace();
          }*/
      }
  
      @Override
      public int getItemCount() {
          return mItems.size();
      }
      class ViewHolder extends RecyclerView.ViewHolder {
          public ImageView imgThumbnail;
          public TextView tvTitle;
          public TextView tvID;
          public TextView tvTime;
          public View item_view;
          public ViewHolder(View itemView) {
              super(itemView);
              imgThumbnail = (ImageView) itemView.findViewById(R.id.img_thumbnail);
              tvTitle = (TextView) itemView.findViewById(R.id.tv_title);
              //tvID = (TextView) itemView.findViewById(R.id.tv_id);
              tvTime = (TextView) itemView.findViewById(R.id.tv_time);
              item_view = itemView;
          }
      }
  }
  </code></pre>