@Override
    protected String doInBackground(String... params) {

      // Notify Parse Analytics that the app has been opened
      ParseAnalytics.trackAppOpenedInBackground(getIntent());

      CardDbHelper cardDbHelper = new CardDbHelper(getBaseContext());

      SQLiteDatabase db = cardDbHelper.getWritableDatabase();
      cardDbHelper.onCreate(db);

      try {
        ParseQuery<ParseObject> query = ParseQuery.getQuery("Card");
        query.setLimit(1000);
        query.selectKeys(Arrays.asList(""));
        List<ParseObject> results = query.find();

        Iterator<ParseObject> iterator = results.iterator();

        // Writing values to DB
        ContentValues values = new ContentValues();

        while (iterator.hasNext()) {
          ParseObject next = iterator.next();
          values.put("cardId", next.getObjectId().toString());
          db.insert(CardDbHelper.TABLE_NAME, "null", values);
        }

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

      return "";
    }
  /** Khoi tao cac thanh phan trong giao dien */
  private void initView() {
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    statuses = getResources().getStringArray(R.array.project_status);
    projectNameInput = (EditText) findViewById(R.id.projectnameInput);
    descriptionInput = (EditText) findViewById(R.id.descriptionInput);
    categoryInput = (EditText) findViewById(R.id.categoryInput);
    listAccessAccount = (ListView) findViewById(R.id.listAccessAccount);
    listCategory = (ListView) findViewById(R.id.listCategories);
    statusInput = (Spinner) findViewById(R.id.statusInput);
    accessAccountInput = (Spinner) findViewById(R.id.accessAccountInput);
    addCategoryBtn = (Button) findViewById(R.id.addCategory);
    addUserBtn = (Button) findViewById(R.id.addAccount);
    delCategoryBtn = (Button) findViewById(R.id.delCategory);
    delUserBtn = (Button) findViewById(R.id.delAccount);
    submitBtn = (Button) findViewById(R.id.submitBtn);

    project = new Project();

    // Lenh truy van cac user trong bang user
    ParseQuery<ParseObject> query = ParseQuery.getQuery(USER_TABLE);

    // Chi lay ra cot username
    query.selectKeys(Collections.singletonList(USER_NAME));

    query.whereGreaterThan(USER_ACCESS_LEVEL, 0);
    query.findInBackground(
        new FindCallback<ParseObject>() {
          @Override
          public void done(final List<ParseObject> objects, ParseException e) {
            // neu khong co loi tra ve
            if (e == null) {
              users = objects;
              for (ParseObject user : users) {
                accessAccounts.add(user.getString(USER_NAME));
              }
              statusInput.setAdapter(
                  new ArrayAdapter<>(
                      getBaseContext(), android.R.layout.simple_dropdown_item_1line, statuses));
              accessAccountInput.setAdapter(
                  new ArrayAdapter<>(
                      getBaseContext(), android.R.layout.simple_list_item_1, accessAccounts));

              addedAccountsAdapter =
                  new ListViewAdapter(getBaseContext(), R.layout.item_lv_layout, addedAccounts);
              listAccessAccount.setAdapter(addedAccountsAdapter);
              SetHeightListView.setListViewHeightBasedOnChildren(listAccessAccount);

              addedCategoriesAdapter =
                  new ListViewAdapter(getBaseContext(), R.layout.item_lv_layout, addedCategories);
              listCategory.setAdapter(addedCategoriesAdapter);
              SetHeightListView.setListViewHeightBasedOnChildren(listCategory);
            }
          }
        });
  }
 private void listPotentialPlayers() {
   final ParseQuery<ParseUser> query = ParseUser.getQuery();
   final Context context = this;
   query.selectKeys(Arrays.asList("username"));
   query.findInBackground(
       new FindCallback<ParseUser>() {
         public void done(List<ParseUser> userList, ParseException e) {
           if (e == null) {
             if (userList != null) {
               List<String> usernameList = new ArrayList<String>();
               for (int i = 0; i < userList.size(); i++) {
                 try {
                   usernameList.add(userList.get(i).getString("username"));
                 } catch (Exception exc) {
                   Log.d(
                       "ScavengerHuntApp",
                       "Problem building user list: " + Log.getStackTraceString(exc));
                 }
               }
               playerList = userList;
               final ArrayAdapter<String> adapter =
                   new ArrayAdapter<String>(
                       context, android.R.layout.simple_list_item_multiple_choice, usernameList);
               final ListView playerListView = (ListView) findViewById(R.id.gamePlayersListView);
               playerListView.setAdapter(adapter);
               playerListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
             }
           } else {
             CharSequence text = "Sorry, there was a problem. Just a sec.";
             int duration = Toast.LENGTH_SHORT;
             Toast.makeText(context, text, duration).show();
             finish();
             startActivity(getIntent());
           }
         }
       });
 }
  @Override
  public void setSemester(String sem) {
    this.semester = sem;
    Toast.makeText(this, semester, Toast.LENGTH_LONG).show();

    ParseQuery<ParseObject> query = ParseQuery.getQuery("Course");
    query.selectKeys(Arrays.asList("courseId", "courseName"));
    query.whereEqualTo("semester", semester);

    try {
      List<ParseObject> result = query.find();

      for (int i = 0; i < result.size(); i++) {
        coursesDetails.put(
            result.get(i).getString("courseId"), result.get(i).getString("courseName"));
        courses.add(
            result.get(i).getString("courseId") + " " + result.get(i).getString("courseName"));
        chk_box_course.put(
            result.get(i).getString("courseId") + " " + result.get(i).getString("courseName"),
            false);
      }
    } catch (ParseException e) {
      e.printStackTrace();
    }

    ListView listView = (ListView) findViewById(R.id.list);
    dataAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, courses);

    // Assign adapter to ListView
    listView.setAdapter(dataAdapter);

    listView.setOnItemClickListener(
        new AdapterView.OnItemClickListener() {
          public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            // When clicked, show a toast with the TextView text
            String course = parent.getItemAtPosition(position).toString();

            ParseObject student_course = ParseObject.create("Student_Course");
            String[] cou = course.split(" ");
            String cid = cou[0];

            student_course.put("courseId", cid);
            student_course.put("studentId", sid);
            student_course.put("attendance", 0);

            student_course.saveInBackground();
            // Log.i("cid",cid);
            // Log.i("sid",sid);

            ParsePush.subscribeInBackground(
                cid,
                new SaveCallback() {
                  @Override
                  public void done(ParseException e) {
                    if (e == null) {
                      // Log.d("com.parse.push", "successfully subscribed to the broadcast
                      // channel.");
                    } else {
                      // Log.e("com.parse.push", "failed to subscribe for push", e);
                    }
                  }
                });

            Toast.makeText(getApplicationContext(), cid + " Added!", Toast.LENGTH_LONG).show();

            Bundle extras = new Bundle();
            extras.putString("id", sid);

            Intent intentStudent = new Intent(AddCourseStudent.this, StudentHome.class);
            intentStudent.putExtras(extras);
            startActivity(intentStudent);
          }
        });
  }