java – CalendarView.getDate() inconsistent behaviour?-ThrowExceptions

Exception or error:

For my app, I want the user to be able to pick a date, or change it, if already picked. When I test this on my Samsung phone (API level 23), it works as expected, but if I test it on an emulated Pixel 2 (API level 24), changing the time doesn’t work.

I’m trying to understand why CalendarView behaves inconsistent when tested on different devices for me. Is it due to an issue with my code (more likely), or an issue with the emulator (less likely)?

Relevant code:

public class RecurringPaymentStartTimePicker extends Activity {
    private long iDate;                                         
    private int iHour;
    private Boolean newRP;

    private CalendarView date;
    private NumberPicker hour;

    protected void onCreate(Bundle saveInstanceState) {


        //either the current date or the previously chosen date
        iDate = super.getIntent().getLongExtra(Init.RECURRING_PAYMENT_ID_CODE+"date", 0);    
        iHour = super.getIntent().getIntExtra(Init.RECURRING_PAYMENT_ID_CODE+"hour", 0);
        newRP = super.getIntent().getBooleanExtra(Init.RECURRING_PAYMENT_ID_CODE+"new", true);

        TextView fixedDate = findViewById(;
        date = findViewById(;
        hour = findViewById(;


        date.setDate(iDate, true, true);
        if (newRP) {
        } else {

        Button confirm = findViewById(;
        Button cancel = findViewById(;

        cancel.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                setResult(Activity.RESULT_CANCELED, prepareIntent());
                overridePendingTransition(R.anim.slide_from_left, R.anim.slide_to_right);

        confirm.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                setResult(Activity.RESULT_OK, prepareIntent());
                overridePendingTransition(R.anim.slide_from_left, R.anim.slide_to_right);

    public Intent prepareIntent() {
        Intent intent = new Intent();
        iDate = date.getDate();
        iHour = hour.getValue();

        intent.putExtra(Init.RECURRING_PAYMENT_ID_CODE+"date", iDate);
        intent.putExtra(Init.RECURRING_PAYMENT_ID_CODE+"hour", iHour);

        return intent;

    public void onBackPressed() {
        Button cancel = findViewById(;

To test the behaviour, I just clicked on a different date than the currently chosen one and then clicked on the confirm button. On my Samsung phone, the date is correctly updated. On the emulated Pixel 2 however, the date did not get updated.

Using the debugger on the Pixel 2 after clicking on a different date, when inspecting element date > mDelegate > mDayPickerView > mTempCalendar > time, it shows as the same date as the CalendarView has been set to initially.

Am I doing something wrong that leads to this inconsistent behaviour, or is it an issue with the emulator?

How to solve:

Leave a Reply

Your email address will not be published. Required fields are marked *