我正在开发一个Android应用程序,其中,当用户单击in按钮时,out按钮应隐藏8个小时或用户指定的小时数,并在8个小时后隐藏[[out按钮应该是可见的,并且如果用户忘记单击out按钮,它应该会自动将他标记出来。
我搜索了有关Android服务的信息,但我不知道如何通过使用服务来实现这一点。感谢您的帮助。
Intent intent = new Intent(activity, AlarmBroadCast.class);
pendingIntent = PendingIntent.getBroadcast(activity, 0, intent, 0);
alarmManager = (AlarmManager) activity.getSystemService(ALARM_SERVICE);
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(System.currentTimeMillis());
calendar.add(Calendar.MINUTE, 2); //Set your time here
alarmManager.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pendingIntent);
//Broadcast reciver
public class AlarmBroadCast extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
//Implement your logic
}
}