简体   繁体   English

android提醒

[英]android reminder

I'm new on android programming and i'm working on reminder application. 我是android编程的新手,正在研究提醒应用程序。 now, i've done storing all information including date and time into SQLlite database. 现在,我已经将所有信息(包括日期和时间)存储到SQLlite数据库中。 my question is how do i match alarm that stored in database with current time on android 我的问题是我如何将存储在数据库中的警报与Android上的当前时间进行匹配

query the data base compare with calendar 查询数据库与日历比较

Calendar c = Calendar.getInstance();
c.set(Calendar.MONTH, Calendar.MARCH);
c.set(Calendar.DAY_OF_MONTH, 3);
long time2=   c.getTimeInMillis();
c.set(Calendar.MONTH, Calendar.AUGUST);
  c.set(Calendar.DAY_OF_MONTH, 8);   
   long time3=   c.getTimeInMillis();
   if(time>time2){
 //Logic
 if(time>time3){
     //Logic
 }
 }

What you need to do is first create the intent you need to schedule. 您需要做的是首先创建需要计划的意图。 Then obtain the pendingIntent of that intent. 然后获取该意图的pendingIntent。 You can schedule activities, services and broadcasts. 您可以安排活动,服务和广播。 To schedule an activity eg MyActivity: 安排活动,例如MyActivity:

  Intent i = new Intent(getApplicationContext(), MyActivity.class);
  PendingIntent pi = PendingIntent.getActivity(getApplicationContext(),3333,i,
  PendingIntent.FLAG_CANCEL_CURRENT);

Give this pendingIntent to alarmManager: 将此alarmIntent赋予alarmManager:

//getting current time and add 5 seconds in it
  Calendar cal = Calendar.getInstance();
  cal.add(Calendar.SECOND, 5);
  //registering our pending intent with alarmmanager
  AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);
  am.set(AlarmManager.RTC_WAKEUP,cal.getTimeInMillis(), pi);

Now MyActivity will be launched after 5 seconds of the application launch, no matter you stop your application or device went in sleep state (due to RTC_WAKEUP option). 现在,无论您停止应用程序还是设备进入睡眠状态(由于RTC_WAKEUP选项),MyActivity都会在应用程序启动5秒后启动。 You can read complete example code Scheduling activities, services and broadcasts #Android 您可以阅读完整的示例代码调度活动,服务和广播#Android

或倒数秒,而不用使用日历或相对的电话时间..我自己做了一个类似的应用,由于电话时间关闭或重置等原因,它似乎减少了变异性...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM