마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

안드로이드 앱에서 특정시간에 DB에 접근하기

0 추천
안드로이드 앱단에서 특정시간에 DB에 접근을 하게 하고 싶습니다.

예를 들어 23:59 -> 00:00 새로운 하루가 시작 될때, 외부 서버 DB에 접근하여 값을 조정하고 싶은데.

 

이떄 안드단에서 어떤식으로 일정 시간이 되었을때 이벤트를 날릴수 있을지 궁금합니다.

안드단 Service로 돌리려 하면 app이 해당 사용자의 폰에서 한번이라도 사용되어야 하는 문제가 있는것 같아서요.. 고수님들의 도움 부탁드립니다.
김트릿 (380 포인트) 님이 2018년 7월 19일 질문

1개의 답변

0 추천

AlarmManager를 사용하여 스케줄링하면 됩니다.

 

private AlarmManager alarmMgr;
private PendingIntent alarmIntent;
...
alarmMgr = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
Intent intent = new Intent(context, AlarmReceiver.class);
alarmIntent = PendingIntent.getBroadcast(context, 0, intent, 0);

// Set the alarm to start at 8:30 a.m.
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(System.currentTimeMillis());
calendar.set(Calendar.HOUR_OF_DAY, 8);
calendar.set(Calendar.MINUTE, 30);

// setRepeating() lets you specify a precise custom interval--in this case,
// 20 minutes.
alarmMgr.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(),
        1000 * 60 * 20, alarmIntent);

여기 링크를 참조하세요 

https://developer.android.com/training/scheduling/alarms

여기는 샘플프로그래입니다.

https://github.com/googlesamples/android-RepeatingAlarm/

luxsoft (1,780 포인트) 님이 2018년 7월 25일 답변
...