Data are not showing in the recyclerview but after turn off and turn on shows list of data
<p>I'm developing an app which I am using volley library to fetch data from server and display in the <code>RecyclerView</code>.. Here I used using four tabs.</p>

<p>The problem is on first run the list of elements to display by getting data from a server, the data loads and gets added to a list but the <code>RecyclerView</code> never displays it. When i turn off the display and turn it back data gets listed in <code>RecyclerView</code></p>

<p>Anyone please help me?</p>

<p>Here's <code>MyAdapter.java</code></p>

<pre><code>public class MyAdapter extends RecyclerView.Adapter&lt;MyAdapter.ViewHolder&gt; {

private ImageLoader mImageLoader;
private Context context;

ArrayList&lt;Coupon&gt; couponArrayList = new ArrayList&lt;&gt;();

public MyAdapter(Context context,ArrayList&lt;Coupon&gt; couponArrayList)
{
    this.couponArrayList=couponArrayList;
    this.context=context;
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    final View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.offer_row,parent,false);
    ViewHolder viewHolder = new ViewHolder(view);

    viewHolder.relativeLayout.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            TextView redUrl = (TextView)view.findViewById(R.id.offer_url);
            String postUrl = redUrl.getText().toString();
            Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(postUrl));
            Intent browserChooserIntent = Intent.createChooser(intent , "Choose browser of your choice");
            context.startActivity(browserChooserIntent);
        }
    });

    return viewHolder;
}

@Override
public void onBindViewHolder(ViewHolder holder, int position) {
    Coupon coupon = couponArrayList.get(position);
    holder.title.setText(coupon.getTitle());
    holder.name.setText(coupon.getName());
    holder.coupon.setText(coupon.getCoupon());
    holder.expiry.setText(coupon.getExpiry());
    holder.url.setText(coupon.getLink());

    //Image loading using singleton class
    mImageLoader = MySingleton.getInstance(context).getImageLoader();
    holder.image.setImageUrl(coupon.getImage(),mImageLoader);
    holder.image.setDefaultImageResId(R.drawable.placeholder_image);
}

@Override
public void onAttachedToRecyclerView(RecyclerView recyclerView) {
    super.onAttachedToRecyclerView(recyclerView);
}
public void remove(ContactsContract.Contacts.Data data) {
    int position = couponArrayList.indexOf(data);
    couponArrayList.remove(position);
    notifyItemRemoved(position);
}

@Override
public int getItemCount() {
    return couponArrayList.size();
}

public static class ViewHolder extends RecyclerView.ViewHolder{
    NetworkImageView image;
    RelativeLayout relativeLayout;
    TextView title,name,coupon,expiry,url;

    public ViewHolder(View itemView) {
        super(itemView);
        this.image = (NetworkImageView)itemView.findViewById(R.id.offer_image);
        this.title = (TextView)itemView.findViewById(R.id.offer_title);
        this.name = (TextView)itemView.findViewById(R.id.offer_name);
        this.coupon = (TextView)itemView.findViewById(R.id.coupon_code);
        this.expiry = (TextView)itemView.findViewById(R.id.expiry_date);
        this.url = (TextView)itemView.findViewById(R.id.offer_url);
        this.relativeLayout = (RelativeLayout)itemView.findViewById(R.id.relLayout);

        //make sure it is clickable
        itemView.setClickable(true);
    }
}
</code></pre>

<p>Here's <code>AllOffers.java</code> (Tab1)</p>

<pre><code>public class AllOffers extends Fragment {
    RequestQueue queue;
    RecyclerView recyclerView;
    RecyclerView.Adapter adapter;
    RecyclerView.LayoutManager layoutManager;
    ArrayList&lt;Coupon&gt; arrayList = new ArrayList&lt;&gt;();

    public AllOffers() {
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.alloffers, container, false);
        recyclerView = (RecyclerView) view.findViewById(R.id.recyclerView);

        layoutManager = new LinearLayoutManager(getContext());
        recyclerView.setLayoutManager(layoutManager);
        recyclerView.setHasFixedSize(true);

        //creating object of BgT to get arraylist og offers &amp; coupons &amp;&amp;asign to local arrayList
        BackgroundTask backgroundTask = new BackgroundTask(getActivity());
        arrayList = backgroundTask.getList();
        adapter = new MyAdapter(getContext(), arrayList);

        //adding horizontal line b/w  rows
        recyclerView.addItemDecoration(new DividerItemDecoration(getContext(), LinearLayoutManager.VERTICAL));

        recyclerView.setAdapter(adapter);
        // adapter.clearAdapter();
        arrayList.clear();

        return view;
    }
}
</code></pre>

<p>Finally the <code>Backgroundtask.java</code></p>

<pre><code>public class BackgroundTask {
    Context context;
    RequestQueue queue;
    public static final String KEY_TITLE="coupon_title";
    public static final String KEY_NAME="offer_name";
    public static final String KEY_CODE="coupon_code";
    public static final String KEY_IMAGE="store_image";
    public static final String KEY_EXPIRY="coupon_expiry";
    public static final String KEY_POSTURL="store_link";

    private ImageLoader mImageLoader;
    ArrayList&lt;Coupon&gt; arrayList = new ArrayList&lt;&gt;();
    public static final String json_url="https://tools.vcommission.com/api/coupons.php?apikey=xxxxxxxxxx";

    public BackgroundTask(Context context) {
        this.context = context;
    }

    public ArrayList&lt;Coupon&gt; getList()
    {
        final JsonArrayRequest  jsonArrayRequest=new JsonArrayRequest(Request.Method.POST, json_url,null,
                new Response.Listener&lt;JSONArray&gt;() {
                    @Override
                    public void onResponse(JSONArray response) {
                        int count=0;
                        while (count&lt;response.length())
                        {
                            try {
                                JSONObject jsonObject= response.getJSONObject(count);
                                Coupon coupon = new Coupon(jsonObject.getString(KEY_TITLE),
                                        jsonObject.getString(KEY_NAME),
                                        jsonObject.getString(KEY_CODE),
                                        jsonObject.getString(KEY_IMAGE),
                                        jsonObject.getString(KEY_EXPIRY),
                                        jsonObject.getString(KEY_POSTURL));

                                arrayList.add(coupon);
                                count++;

                            } catch (JSONException e) {
                                e.printStackTrace();
                            }
                        }
                    }
                }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                Toast.makeText(context,"No internet connection...!!!",Toast.LENGTH_LONG).show();
                error.printStackTrace();
            }
        });
        MySingleton.getInstance(context).addToRequestQueue(jsonArrayRequest);

        return arrayList;
    }
}
</code></pre>