안녕하세요. 밑에도 글을 올렸는데 Receiver에서 BOOT_COMPLETED할때, 임의의 동작을 계속계속하는 프로그램을 작성하고있습니다.
돌다가 특정위치(정확히는 모르겠지만..)에서 멈추어버립니다. 왜그런가요..ㅜㅜ
< AndroidManifest.xml >
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="android.app.BackService"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".BackService" android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name=".MyStartupIntentReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<category android:name="android.intent.category.HOME" />
</intent-filter>
</receiver>
<service android:name=".detectActivityService">
<intent-filter>
<action android:name=".detectActivityService" />
</intent-filter>
</service>
</application>
<uses-sdk android:minSdkVersion="3" />
</manifest>
<Source>
리시버쪽 소스입니다.
public class MyStartupIntentReceiver extends BroadcastReceiver{
public void onReceive(Context context, Intent intent)
{
if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction() ))
{
Log.w("Receiver IN", " ");
Intent serviceIntent = new Intent();
serviceIntent.setAction(".detectActivityService");
context.startService(serviceIntent);
}
}
}
서비스쪽 소스입니다.
public class detectActivityService extends Service {
public void onStart(Intent intent, int startId){
super.onStart(intent, startId);
while(true)
{
Log.w(" Service ", " Running ");
SystemClock.sleep(500);
}
}
public void onDestroy() {
super.onDestroy();
Log.w("Destroy", " ");
}
public void onCreate(){
Log.w("Service Create", " ");
}
public IBinder onBind(Intent intent){
return null;
}
}
sleep는 너무빨리 돌아 임시로 하였습니다.
<Log Cat>
08-10 09:49:22.869: INFO/ActivityManager(570): Start proc android.app.BackService for broadcast android.app.BackService/.MyStartupIntentReceiver: pid=683 uid=10019 gids={}
08-10 09:49:23.459: WARN/Receiver IN(683):
08-10 09:49:23.499: WARN/Service Create(683):
08-10 09:49:23.529: WARN/Service(683): Running
08-10 09:49:23.719: INFO/ActivityManager(570): Stopping service: com.android.providers.downloads/.DownloadService
08-10 09:49:23.799: WARN/Service(683): Running
..........................................................................................................................
08-10 09:49:20.767: WARN/Service(683): Running
08-10 09:49:20.776: DEBUG/ActivityManager(570): Force removing process ProcessRecord{4373d608 683:android.app.BackService/10019} (android.app.BackService/10019)
08-10 09:49:20.786: WARN/ActivityManager(570): Scheduling restart of crashed service android.app.BackService/.detectActivityService in 5000ms
08-10 09:49:20.786: INFO/Process(570): Sending signal. PID: 683 SIG: 9
08-10 09:49:20.816: DEBUG/ActivityManager(570): Received spurious death notification for thread android.os.BinderProxy@435a58b0
08-10 09:49:20.816: ERROR/ActivityThread(570): Failed to find provider info for android.server.checkin
08-10 09:49:20.816: WARN/Checkin(570): Can't log event SYSTEM_SERVICE_LOOPING: java.lang.IllegalArgumentException: Unknown URL content://android.server.checkin/events
08-10 09:49:20.827: DEBUG/HomeLoaders(613): application intent received: android.intent.action.PACKAGE_REMOVED, replacing=true
08-10 09:49:20.837: DEBUG/HomeLoaders(613): --> package:android.app.BackService
08-10 09:49:20.847: WARN/ResourceType(570): No package identifier when getting value for resource number 0x7f060000
08-10 09:49:20.876: WARN/ResourceType(570): No package identifier when getting value for resource number 0x7f060001
08-10 09:49:20.907: DEBUG/HomeLoaders(613): application intent received: android.intent.action.PACKAGE_ADDED, replacing=true
08-10 09:49:20.907: DEBUG/HomeLoaders(613): --> package:android.app.BackService
08-10 09:49:20.907: DEBUG/HomeLoaders(613): --> update package android.app.BackService
08-10 09:49:21.136: DEBUG/dalvikvm(570): GC freed 2453 objects / 128104 bytes in 189ms
08-10 09:49:21.136: DEBUG/KeyguardViewMediator(570): pokeWakelock(5000)
08-10 09:49:21.197: WARN/ResourceType(570): No package identifier when getting value for resource number 0x7f060000
08-10 09:49:21.207: WARN/ResourceType(570): No package identifier when getting value for resource number 0x7f060001
08-10 09:49:21.287: INFO/ActivityManager(570): Start proc com.android.inputmethod.latin for service com.android.inputmethod.latin/.LatinIME: pid=713 uid=10003 gids={3003}
08-10 09:49:21.317: INFO/ARMAssembler(570): generated scanline__00000077:03545404_00000A04_00000000 [ 29 ipp] (51 ins) at [0x23ff48:0x240014] in 4961188 ns
08-10 09:49:21.816: DEBUG/AndroidRuntime(712): >>>>>>>>>>>>>> AndroidRuntime START <<<<<<<<<<<<<<
08-10 09:49:21.837: DEBUG/AndroidRuntime(712): CheckJNI is ON
08-10 09:49:21.937: DEBUG/dalvikvm(713): Trying to load lib /system/lib/libjni_latinime.so 0x43598010
08-10 09:49:21.956: DEBUG/dalvikvm(713): Added shared lib /system/lib/libjni_latinime.so 0x43598010
08-10 09:49:22.146: DEBUG/AndroidRuntime(712): --- registering native functions ---
08-10 09:49:22.707: INFO/ActivityManager(570): Starting activity: Intent { flags=0x10000000 comp={android.app.BackService/android.app.BackService.BackService} }
도와주세요. 감사합니다. ^^
On current Android devices, we can keep only a small handful of applications
running at the same time. Having your application do this is going to going
to take resources from other things that at any particular point in time
would be better used elsewhere. And in fact, you can be guaranteed that
your service will -not- stay running all of the time, because there is so
much other stuff that wants to run (other background services that are only
running when needed will be prioritized over yours), or needs more memory
for what the user is actually doing (running the web browser on complicated
web pages is a great way to kick background stuff out of memory).
We have lots of facilities for implementing applications so they don't need
to do this, such as alarms, and various broadcasts from events going on in
the system. Please please please use them if at all possible. Having a
service run forever is pretty close to the side of evil.