2016-12-05 115 views
0

我不知道如何表达自己对这个疑问很好,但我会尽力。Android - 24小时工作时间间隔

我的应用程序将有各种任务(托管在数据库上),用户必须尝试使它们。

我希望应用程序能够随时随地从数据库中进行任务更新并在24小时内将其显示在应用程序中,然后在24小时后显示另一个等,我认为您现在了解它。

我该如何做到这一点?

我搜索了网页,我无法找到任何适合我需要的东西。

回答

0

使用本

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 
     } 
1

您存储用户手机上的时间戳。当他登录时,将时间戳与当前时间进行比较。如果有24小时过去了,则更新任务和存储的时间戳。

0

你可以使用一个TimerTask方法,设置firstTime到时候你要刷新taskand设定的期限为24小时像

Timer.schedule(TimerTask task, Date firstTime, long period) 

然后做你随意的事情挑一个新的任务和标志这是一个积极的。