开发者

I want this to be checked over and over again during android until it equals on android

    public void time() {

        Calendar c_enter = Calendar.getInstance();
        c_enter.add(Calendar.DAY_OF_YEAR, 0);
        c_enter.set(Calendar.HOUR_OF_DAY, 0);
        c_enter.set(Calendar.MINUTE, 0);
        c_enter.set(Calendar.SECOND, 0);
        c_enter.set(Calendar.MILLISECOND, 0);

        Calendar c_expected = Calendar.getInstance();
        c_expected.add(Calendar.DAY_OF_YEAR, 0);
        c_expected.set(Calendar.HOUR_OF_DAY, 0);
        c_expected.set(Calendar.MINUTE, 0);
        c_expected.set(Calendar.SECOND, 0);
        c_expected.set(Calendar.MILLISECOND, 0);

        c_expected.getTime();
        c_enter.getTime();

        while (!c_enter.equals(c_expected开发者_开发知识库)) {
            if (c_enter.equals(c_expected)) {
                Toast.makeText(this, "Incorrect version. Please update.",
                        Toast.LENGTH_SHORT).show();
            }
        }
    }

but it doesn't toast in the activity when 30 seconds has passed. Be gentle, android while noobie.

on Android.


Even if this code were correct, a while loop is hardly the correct approach to initiating a time-based action. While this is also true on the desktop, this is especially so on a mobile phone, since busy waiting in a while loop consumes a lot more battery than using a proper timer. What you want is a simple CounDownTimer which will automatically invoke the onFinish function when the time is up.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜