private void setNotification() {
    Intent intent = new Intent();
    Calendar calendar = Calendar.getInstance();
    if (dMonth == 0) {
      String date[] = postDate.split("-");
      dDay = Integer.parseInt(date[0]);
      dMonth = Integer.parseInt(date[1]) - 1;
      dYear = Integer.parseInt(date[2]);
    }

    // Set the calendar at the desired time and day
    calendar.set(Calendar.MONTH, dMonth);
    calendar.set(Calendar.DAY_OF_MONTH, dDay);
    calendar.set(Calendar.YEAR, dYear);
    calendar.set(Calendar.HOUR_OF_DAY, dHour);
    calendar.set(Calendar.MINUTE, dMin);
    calendar.set(Calendar.SECOND, 0);

    AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);

    intent.setClass(getApplicationContext(), Notify.class);
    titleName = etTitle.getText().toString();

    // Send title text to the Service class
    intent.putExtra(AppConfig.TITLE, postTitle);
    notifId = (long) System.currentTimeMillis();

    // set title number into the sharedpreferences
    titleSufix = Integer.toString(NotificationPreference.getPosition("Tnr", this));
    NotificationPreference.save(AppConfig.TITLE_NOTIFICATION + titleSufix, titleName, this);
    PendingIntent pendingIntent =
        PendingIntent.getService(
            getApplicationContext(), (int) notifId, intent, PendingIntent.FLAG_UPDATE_CURRENT);

    alarmManager.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pendingIntent);
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_manage_bill);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    // Initializations
    lType = (LinearLayout) findViewById(R.id.lType);
    cbNotification = (CheckBox) findViewById(R.id.cbNotification);
    spCategory = (Spinner) findViewById(R.id.spBCategory);
    rgType = (RadioGroup) findViewById(R.id.rgBType);
    rbBPayable = (RadioButton) findViewById(R.id.rbPay);
    rbBPaid = (RadioButton) findViewById(R.id.rbBPaid);
    etDate = (EditText) findViewById(R.id.etBDate);
    btnCancel = (Button) findViewById(R.id.btnBCancel);
    btnSave = (Button) findViewById(R.id.btnBSave);
    etTitle = (EditText) findViewById(R.id.etBTitle);
    etNotes = (EditText) findViewById(R.id.etBNotes);
    etTime = (EditText) findViewById(R.id.etBTime);
    lTime = (LinearLayout) findViewById(R.id.layTime);
    etAmount = (EditText) findViewById(R.id.etBAmount);

    NotificationPreference.setDefault(this);

    cbNotification.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            hideCBNotification();
          }
        });

    // set bill as payable
    rbBPayable.setChecked(true);
    paymentType = AppConfig.PAYABLE;

    ArrayAdapter array =
        new ArrayAdapter(manage_bill.this, android.R.layout.simple_list_item_1, categories);

    spCategory.setAdapter(array);
    spCategory.setOnItemSelectedListener(
        new AdapterView.OnItemSelectedListener() {
          @Override
          public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            categoryName = categories[position];
          }

          @Override
          public void onNothingSelected(AdapterView<?> parent) {}
        });

    rgType.setOnCheckedChangeListener(
        new RadioGroup.OnCheckedChangeListener() {
          @Override
          public void onCheckedChanged(RadioGroup group, int checkedId) {
            checkRBType(checkedId);
          }
        });

    etDate.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            Calendar calendar = Calendar.getInstance();
            new DatePickerDialog(
                    manage_bill.this,
                    listener,
                    calendar.get(Calendar.YEAR),
                    calendar.get(Calendar.MONTH),
                    calendar.get(Calendar.DAY_OF_MONTH))
                .show();
          }
        });

    etDate.setOnFocusChangeListener(
        new View.OnFocusChangeListener() {
          @Override
          public void onFocusChange(View v, boolean hasFocus) {
            if (hasFocus) {
              Calendar calendar = Calendar.getInstance();
              new DatePickerDialog(
                      manage_bill.this,
                      listener,
                      calendar.get(Calendar.YEAR),
                      calendar.get(Calendar.MONTH),
                      calendar.get(Calendar.DAY_OF_MONTH))
                  .show();
            }
          }
        });

    etTime.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            Calendar calendar = Calendar.getInstance();
            new TimePickerDialog(
                    manage_bill.this,
                    timelistener,
                    calendar.get(Calendar.HOUR_OF_DAY),
                    calendar.get(Calendar.MINUTE),
                    false)
                .show();
          }
        });

    etTime.setOnFocusChangeListener(
        new View.OnFocusChangeListener() {
          @Override
          public void onFocusChange(View v, boolean hasFocus) {
            if (hasFocus) {
              Calendar calendar = Calendar.getInstance();
              new TimePickerDialog(
                      manage_bill.this,
                      timelistener,
                      calendar.get(Calendar.HOUR_OF_DAY),
                      calendar.get(Calendar.MINUTE),
                      false)
                  .show();
            }
          }
        });

    btnCancel.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            finish();
          }
        });

    btnSave.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            // Make sure that the fields are filled
            attemptManageBill();
          }
        });

    // Check if we need to add a new bill or modify it
    Intent intent = getIntent();
    if (intent.hasExtra(AppConfig.BILL_ID)) {
      Bundle bundle = getIntent().getExtras();
      if (!bundle.getString(AppConfig.BILL_ID).equals(null)
          && !TextUtils.isEmpty(bundle.getString(AppConfig.BILL_ID))) {

        billId = bundle.getString(AppConfig.BILL_ID);
        prepareToModify();
      }
    }
  }