안드로이드 개발 질문/답변
(글 수 40,700)
안드로이드에서는 윈도우의 시작프로그램과 같은 프로그램을 만들수 있는지 궁굼합니다.~
지금 스케줄 관리 프로그램을 만들어 볼려고 하는데요!! 알람 설정을하게 되면 해당 날자 또는 시간에 알람 메시지를
보여주려고 합니다.
SDK에 있는 ApiDemos에 AlarmService 와 같은 서비스기능을 참고 해 봤지만 버튼을 클릭해야만 서비스가 시작되는데요!
제가 원하는것은 안드로이드가 시작됨과 동시에 프로그램이 호출되서 데몬 형태로 프로그램이 서비스 되도록 하고 싶은겁니다.!
설명을 잘 하고 싶은데 머리속에서만 자꾸 맴도네요 ^^; 죄송합니다. ㅎㅎ 제가 구연하고자 하는 부분이 가능할까요??
지금 스케줄 관리 프로그램을 만들어 볼려고 하는데요!! 알람 설정을하게 되면 해당 날자 또는 시간에 알람 메시지를
보여주려고 합니다.
SDK에 있는 ApiDemos에 AlarmService 와 같은 서비스기능을 참고 해 봤지만 버튼을 클릭해야만 서비스가 시작되는데요!
제가 원하는것은 안드로이드가 시작됨과 동시에 프로그램이 호출되서 데몬 형태로 프로그램이 서비스 되도록 하고 싶은겁니다.!
설명을 잘 하고 싶은데 머리속에서만 자꾸 맴도네요 ^^; 죄송합니다. ㅎㅎ 제가 구연하고자 하는 부분이 가능할까요??
2009.04.28 03:03:11
BOOT_COMPLETED Intent에 대한 Receiver 설정을 해주면 가능합니다. Intent 레퍼런스 문서에서 관련 설명을 한번 읽어보세요.
2009.04.29 11:49:37
참고로 저와 같은 고민을 하고 계시는 분은 이걸 참조 하세요 ^^;
1.when the OS starts, it will send a Standard Broadcast Action named android.intent.action.BOOT_COMPLETED.
2.construct a class extended from IntentReceiver to catch the action, and override its abstract method onReceiveIntent(Context context, Intent intent), where you can put your start service code in.
3.in AndroidManifest.xml, you should add tag
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"></uses-permission>
to get the permission of android.intent.action.BOOT_COMPLETED.
In additon, you should add tag
<action android:name="android.intent.action.BOOT_COMPLETED" />
in the <intent-filter> of your IntentReceiver class.
code example:
xml:
java:
1.when the OS starts, it will send a Standard Broadcast Action named android.intent.action.BOOT_COMPLETED.
2.construct a class extended from IntentReceiver to catch the action, and override its abstract method onReceiveIntent(Context context, Intent intent), where you can put your start service code in.
3.in AndroidManifest.xml, you should add tag
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"></uses-permission>
to get the permission of android.intent.action.BOOT_COMPLETED.
In additon, you should add tag
<action android:name="android.intent.action.BOOT_COMPLETED" />
in the <intent-filter> of your IntentReceiver class.
code example:
xml:
Code: |
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"></uses-permission>
<receiver android:name=".OlympicsReceiver" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </receiver> |
java:
Code: |
public class OlympicsReceiver extends IntentReceiver
{ /* the intent source*/ static final String ACTION = "android.intent.action.BOOT_COMPLETED"; public void onReceiveIntent(Context context, Intent intent) { if (intent.getAction().equals(ACTION)) { context.startService(new Intent(context, OlympicsService.class), null); //start my your service here
Toast.makeText(context, "OlympicsReminder service has started!", Toast.LENGTH_LONG).show(); } } } |