@TargetApi(Build.VERSION_CODES.LOLLIPOP)
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    userState = UserProfile.getUserState(this);
    redirectUser(userState);

    setContentView(R.layout.ac_main);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    final ActionBar ab = getSupportActionBar();
    //        ab.setHomeAsUpIndicator(R.drawable.ic_menu);
    //        ab.setDisplayHomeAsUpEnabled(true);

    //        mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);

    /* swipeContainer = (SwipeRefreshLayout) findViewById(R.id.swipeContainer);
    swipeContainer.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
            // Your code to refresh the list here.
            // Make sure you call swipeContainer.setRefreshing(false)
            // once the network request has completed successfully.
            //fetchTimelineAsync(0);
        }
    });*/

    //        NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    //        if (navigationView != null) {
    //            setupDrawerContent(navigationView);
    //        }

    ViewPager viewPager = (ViewPager) findViewById(R.id.viewpager);
    if (viewPager != null) {
      setupViewPager(viewPager);
    }

    //        FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    //        fab.setBackgroundTintList(ColorStateList.valueOf(Color.parseColor("#3F51B5")));
    //        fab.setOnClickListener(new View.OnClickListener() {
    //            @Override
    //            public void onClick(View view) {
    //                Snackbar.make(view, "Here's a Snackbar", Snackbar.LENGTH_LONG)
    //                        .setAction("Action", null).show();
    //            }
    //        });

    TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);
    tabLayout.setTabMode(TabLayout.MODE_SCROLLABLE);
    tabLayout.setupWithViewPager(viewPager);

    if (checkPlayServices()) {
      // Start IntentService to register this application with GCM.
      Intent intent = new Intent(this, IE_RegistrationIntentService.class);
      startService(intent);
    }

    if (Connectivity.isNetworkAvailable(MainActivity.this)) {
      new RefreshRequest().execute();
    }
  }
    @Override
    protected Void doInBackground(String... strings) {

      Intent intent = new Intent(MainActivity.BROADCAST_UPDATE);

      params.add(new PostParam("time", SPUtils.getLastUpdateDate(MainActivity.this)));
      JSONObject json =
          PostRequest.execute(
              URLConstants.URL_REFRESH, params, UserProfile.getUserToken(MainActivity.this));
      try {
        Log.d(LOG_TAG, " Last updated on " + SPUtils.getLastUpdateDate(MainActivity.this));
        Log.d(LOG_TAG, json.toString());
        status = json.getInt("status");
      } catch (JSONException e) {
        e.printStackTrace();
      }
      if (status == 200) {
        try {
          Log.d(LOG_TAG, "Status:" + String.valueOf(status));
          Log.d(LOG_TAG, json.toString());
          json = json.getJSONObject("data");
          Events = json.getJSONArray("events");
          for (int i = 0; i < Events.length(); i++) {
            JSONObject json1 = Events.getJSONObject(i);
            event = new Event(json1);
            event.saveEvent(MainActivity.this);
          }
          intent.putExtra("code", "events");
          if (Events.length() > 0)
            LocalBroadcastManager.getInstance(MainActivity.this).sendBroadcast(intent);

        } catch (JSONException e) {
          e.printStackTrace();
        }

        try {
          jScoreBoards = json.getJSONArray("scoreboard");
          for (int j = 0; j < jScoreBoards.length(); j++) {
            jScoreBoard = jScoreBoards.getJSONObject(j);
            category = jScoreBoard.getString("category");
            jScoreCards = jScoreBoard.getJSONArray("scorecard");
            scoreBoardId = jScoreBoard.getString("_id");

            for (int k = 0; k < jScoreCards.length(); k++) {
              jScoreBoard = jScoreCards.getJSONObject(k);
              ContentValues cv =
                  ScoreCard.getCV(
                      category,
                      jScoreBoard.getJSONObject("hostel").getString("name"),
                      jScoreBoard.getInt("score"),
                      scoreBoardId + jScoreBoard.getString("_id"));
              ScoreCard.saveScoreCard(MainActivity.this, cv);
            }
          }
          intent = new Intent(MainActivity.BROADCAST_UPDATE);
          intent.putExtra("code", "scoreboards");
          if (jScoreBoards.length() > 0)
            LocalBroadcastManager.getInstance(MainActivity.this).sendBroadcast(intent);

        } catch (JSONException e) {
          e.printStackTrace();
        }

        try {
          Clubs = json.getJSONArray("clubs");
          for (int i = 0; i < Clubs.length(); i++) {
            jClub = Clubs.getJSONObject(i);
            club = gson.fromJson(jClub.toString(), Club.class);
            Log.d(LOG_TAG, jClub.getString("name"));
            DatabaseHelper data = new DatabaseHelper(MainActivity.this);
            data.addClub(club.getCV());
          }
          intent = new Intent(MainActivity.BROADCAST_UPDATE);
          intent.putExtra("code", "clubs");
          if (Clubs.length() > 0)
            LocalBroadcastManager.getInstance(MainActivity.this).sendBroadcast(intent);
        } catch (JSONException e) {
          e.printStackTrace();
        }

        SPUtils.setLastUpdateDate(MainActivity.this);
      }
      return null;
    }