Notice
Link
- Today
- Total
Recent Posts
Recent Comments
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- sql exception
- view 획득
- 말줌임 CSS
- 터치좌표 view
- 피쉬랜드
- CentOS
- MFC
- ffmpeg
- Back 키 클릭 감지
- 시간대별 통계
- 스크롤적용
- rn
- vc++
- c언어
- 코드로 서버 재실행
- CSS
- 파티션 빠른 삭제
- springboot 재가동
- MariaDB
- pid 찾아 kill
- mybatis exception
- MySQL
- springboot
- group by
- 가변영역 스크롤
- kill -9
- 시간대 테이블생성
- SQL
- Activity 전체화면
- reactnative
Archives
개발은 하는건가..
[Android] AlarmManager 의 RTC_WAKEUP 을 통한 작업 수행. 본문
반응형
설정 시간 이후 깨어나서 필요한 동작을 수행하도록 한다.
요즘 추세는 WAKEUP 을 하지 않고 WorkManager 를 이용하라고는 하지만 여전히 잘 동작하고 옛날 방식이 더 편한 감도 있다.
AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
Intent newIntent = new Intent(Constants.DELAYED_ALARM_WAKE_UP);
newIntent.setPackage(getPackageName());
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, newIntent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE);
timeDiff += System.currentTimeMillis();
alarmManager.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, timeDiff, pendingIntent);
timeDiff 시간 이후 Constants.DELAYED_ALARM_WAKE_UP action 을 수신할 수 있는 BroadcastReceiver 만 생성하여 사용하면 된다.
BroadcastReceiver mReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (action.equals(Constants.DELAYED_ALARM_WAKE_UP)) {
// TODO. 동작 처리.
}
}
}
예전에는 PendingIntent 생성 시 플래그를 0 으로 설정해도 문제가 없었는데 요즘은 PendingIntent.FLAG_IMMUTABLE 플래그를 설정해야 마켓 등록 시 퇴짜 맞지 않는다.
'Java, Android' 카테고리의 다른 글
Back버튼 클릭 리스너 등록하기 (0) | 2024.04.22 |
---|---|
Activity 전체 화면으로 사용, Back, Home 버튼 UI 감추기 (0) | 2024.04.22 |
Android 화면 회전(ScreenRotation) (0) | 2022.07.19 |
Android 전체 화면 노치 영역 사용 설정하기 (0) | 2022.07.01 |
Android View Animation stop 또는 재시작 (0) | 2022.06.21 |
Comments