runtime - 应用程序关闭时是否可以运行计时器任务?
问题描述
我刚刚完成了 Java 的学习,现在我正在开发 Android 应用程序。但我在这个领域不是那么专家。我刚刚创建了一个 Android 应用程序,其中包含一些广告,例如横幅广告、插页式广告。如果用户观看视频广告,我想给他们一个机会在 24 小时内停止这些广告。但我不熟悉计时器任务,任何建议都会非常感激。这是我想象的代码:
// load from shared preference
SharedPreference spref = getSharedPreference("directory_name", 0);
if(spref.getBoolean("ad_key", false)==true){
// all ads should stop showing
}else{
// ads are showing
}
// help me here in timer task
As ad reward
--> start countadown
--> if(countDown>0){
doneWatchindAd(true);
}else{
doneWatchindAd(false);
}
// store to shared preference
public void doneWatchindAd(bollean cond){
SharedPreference spref = getSharedPreference("directory_name", 0);
SharedPreference.Editor editor = spref.edit();
editor.putBoolean("ad_key", cond);
editor.commit();
}
解决方案
推荐阅读
- javascript - 复制 URL 参数并将它们注入另一个 URL
- python - ModuleNotFoundError:没有名为“wtforms”的模块
- azure-devops-pipelines - 在 Azure devops 管道中设置变量后无法立即打印该变量
- python - TfidfVectorizer:获取 features_name 的顶级字典和值
- sql - 如何在 BigQuery 中使用 IF 脚本检查查询结果?
- javascript - 如何在 HERE 地图中使用 lineString 坐标?
- java - Java的“单文件模式”是否有可能拥有多个源文件?
- java - IntelliJ IDEA 看不到从子项目中的 protobuf 文件生成的类
- android - OTP 自动检测在 Firebase 电话号码身份验证中不起作用
- r - 图表内的文字