【发布时间】:2017-04-20 03:28:09
【问题描述】:
对于这个疑问,我不知道如何表达自己,但我会尽力而为。
我的应用程序将包含用户必须尝试完成的各种任务(托管在数据库中)。
我希望应用程序使用数据库中的随机任务更新任务,并在 24 小时内将其显示在应用程序上,然后在 24 小时后显示另一个,等等,我想你现在明白了。
我怎样才能做到这一点?
我在网上搜索,但找不到任何适合我需要的东西。
【问题讨论】:
标签: android sqlite time intervals
对于这个疑问,我不知道如何表达自己,但我会尽力而为。
我的应用程序将包含用户必须尝试完成的各种任务(托管在数据库中)。
我希望应用程序使用数据库中的随机任务更新任务,并在 24 小时内将其显示在应用程序上,然后在 24 小时后显示另一个,等等,我想你现在明白了。
我怎样才能做到这一点?
我在网上搜索,但找不到任何适合我需要的东西。
【问题讨论】:
标签: android sqlite time intervals
使用这个
public static void setAlarm(Context context, String action, int actionCode, long syncTime)
{
AlarmManager alarmMgr = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
Intent intent = new Intent(action);
intent.putExtra(ACTION, actionCode);
PendingIntent alarmIntent = PendingIntent.getBroadcast(context, actionCode + 1000, intent, 0);
alarmMgr.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + syncTime, syncTime, alarmIntent);
}
public class AlarmIntentReceiver extends BroadcastReceiver
{
@Override
public void onReceive(Context context, Intent intent)
{
int action = intent.getIntExtra(AlarmUtil.ACTION, 0);
//Perform action here
}
【讨论】:
您将时间戳存储在用户手机上。当他登录时,您将时间戳与当前时间进行比较。如果过了 24 小时,您将更新任务和存储的时间戳。
【讨论】:
您可以使用 TimerTask 方法,将 firstTime 设置为您要刷新任务的时间,并将周期设置为 24 小时,例如
Timer.schedule(TimerTask task, Date firstTime, long period)
然后随机选择一个新任务并将其标记为活跃。
【讨论】: