gpt4 book ai didi

android - 如何克服每秒显示 Toast 时的显示滞后

转载 作者:行者123 更新时间:2023-11-29 17:42:00 25 4
gpt4 key购买 nike

我的 Toast 与 Timer 秒数不同步,如何克服显示延迟

CountDownTimer timer = new CountDownTimer(20000, 1000) {
@Override
public void onTick(long millisUntilFinished) {
Toast.makeText(getApplicationContext(), "Disabling Password, Please wait : " + millisUntilFinished/1000, Toast.LENGTH_SHORT).show();
}

@Override
public void onFinish() {
Log.d("Admin", "Disabling Password");
devicePolicyManager.setPasswordQuality(demoDeviceAdmin,DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED);
devicePolicyManager.setPasswordMinimumLength(demoDeviceAdmin, 0);
boolean resulttwo = devicePolicyManager.resetPassword("", DevicePolicyManager.RESET_PASSWORD_REQUIRE_ENTRY);
Log.d("Admin", "Disabling Password : " + resulttwo);
Toast.makeText(getApplicationContext(), "Congratulations!! Password Disabled", Toast.LENGTH_SHORT).show();
}
}.start();

最佳答案

Toast提供了取消方法,

定义mToast为数据成员并初始化为null

 CountDownTimer timer = new CountDownTimer(20000, 1000) {
@Override
public void onTick(long millisUntilFinished) {
if (mToast != null) {
mToast.cancel();
}
mToast = Toast.makeText(getApplicationContext(), "Disabling Password, Please wait : " + millisUntilFinished / 1000, Toast.LENGTH_SHORT);
mToast.show();
Log.d("Admin", "Disabling Password, Please wait : " + millisUntilFinished / 1000);
}

@Override
public void onFinish() {
Log.d("Admin", "Disabling Password");
devicePolicyManager.setPasswordQuality(demoDeviceAdmin,DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED);
devicePolicyManager.setPasswordMinimumLength(demoDeviceAdmin, 0);
boolean resulttwo = devicePolicyManager.resetPassword("", DevicePolicyManager.RESET_PASSWORD_REQUIRE_ENTRY);
Log.d("Admin", "Disabling Password : ");
if (mToast != null) {
mToast.cancel();
}
mToast = Toast.makeText(getApplicationContext(), "Congratulations!! Password Disabled", Toast.LENGTH_SHORT);
mToast.show();
}
}.start();

关于android - 如何克服每秒显示 Toast 时的显示滞后,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28339861/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com