- Today
- Total
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 29 | 30 |
- 재능이의 돈버는 일기
- StresslessLife
- K_JIN2SM
- 소소한 일상
- My Life Style & Memory a Box
- Blog's generation
- 공감 스토리
- 취객의 프로그래밍 연구실
- Love Me
- Dream Archive
- 세상에 발자취를 남기다 by kongmingu
- hanglesoul
- 카마의 IT 초행길
- 느리게.
- 미친듯이 즐겨보자..
- Joo studio
- Gonna be insane
- 악 다 날아갔어!! 갇대밋! 왓더...
- xopowo05
- 맑은공기희망운동
- 엔지니어 독립운동
- 혁준 블로그
- Simple in Complex with Simple
- 무의식이 의식을 지배한다
드럼치는 프로그래머
[안드로이드] 부팅시점에 안드로이드 서비스 시작 본문
A service that has to be started manually is an oxymoron, so starting a service at boot time is for many applications a must.
My tracklogging service is such an example, which should run whenever the phone is turned on, so that one can refer to the route travelled later. A further example is the much touted CarbonFootprint, which again relies on accurate measurements all the time, and not just when the user has turned it on.
The last post detailed how the TrackloggingService worked, but started the service only when the main activity was launched. Now comes the time to hook it into the Android boot sequence. Here is how:
After boot completes the Android system broadcasts an intent with the action android.intent.action.BOOT_COMPLETED. And now all we need is an IntentReceiver, now called a BroadcastReceiver, to listen and act on it. This is how this class looks:
The key is of course the onReceive() method. I have decided to check that it is actually the Intent I am expecting, but otherwise it is straightforward starting the service and return.
The receiver needs to be declared in the manifest, e.g. with the following entry:
Furthermore this class listen to this specific event needs to be declared in the security settings:
That's it. Now the service will be started as soon a Android has finished booting.
Now we will need something to make this user-configurable...
'★─Programing > ☆─Android' 카테고리의 다른 글
[안드로이드] Android Service 및 AIDL (0) | 2013.04.19 |
---|---|
[안드로이드] 매니페스트파일 설정(AndroidManifest.xml) (0) | 2013.04.17 |
[안드로이드] Notification (안드로이드 알림) (0) | 2013.04.01 |
[안드로이드] Remote Service 사용하기 (0) | 2013.04.01 |
[안드로이드] 죽지 않는 서비스 만들기 (0) | 2013.04.01 |