Android服务死然后自动重启并且工作正常

时间:2011-09-09 23:37:45

标签: android service broadcastreceiver

我是一个非常棒的Android开发世界,也是Java的新手,我想开发和在“X”分钟后挂断电话的应用程序。

我做了一个BroadcastReceiver来捕获新的呼叫,然后调用一个睡眠时间为“X”分钟的服务,然后挂断电话。

我的问题是,当BradcastReceiver启动服务时,服务会运行,但是大约10-12秒后它就会死机,然后自动启动就完成了。

这是我的代码:

广播接收器

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.TelephonyManager;

public class PhoneCallReceiverOutgoing extends BroadcastReceiver {

public void onReceive(Context context, Intent intent) {

    // Get extra values
    String dialedNumber = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER).toString();

    if (dialedNumber != null) {

        System.out.println("|#| **** PhoneCallReceiverOut - New call to: " + dialedNumber + " **** |#|");
        System.out.println("|#| **** PhoneCallReceiverOut - Se inicia el Servicio **** |#|");
        //Intent serviceIntent = new Intent(context,PhoneCallService.class);
        Intent serviceIntent = new Intent();
        serviceIntent.setClass(context,PhoneCallService.class);
            context.startService(serviceIntent);
            System.out.println("|#| **** PhoneCallReceiverOut - Saliendo del Receiber **** |#|");                       
        }
    }
}

这是我的服务:

import java.lang.reflect.Method;

import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.os.IBinder;
import android.os.SystemClock;
import android.telephony.TelephonyManager;

import com.android.internal.telephony.ITelephony;

public class PhoneCallService extends Service {

@Override
public IBinder onBind(Intent arg0) {
    // TODO Auto-generated method stub
    System.out.println("|#| **** PhoneCallService - onBind **** |#|");
    return null;
}


public void onCreate() {
    // Do something
    super.onCreate();
    System.out.println("Service init");
}

public void onStart(Intent intent, int serviceId) {

    super.onStart(intent, serviceId);
    System.out.println("|#| **** PhoneCallService - Starting service **** |#|");

    // Testing with 2 minutes
    int minutes = 2,seconds = 0;
    seconds = minutes * 60000;
    System.out.println("|#| **** PhoneCallService - End call in : " + minutes + " minutes ( " + seconds + " seconds) **** |#|");
    SystemClock.sleep(seconds);

    TelephonyManager tm = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
    try {
        Class c = Class.forName(tm.getClass().getName());
        Method m = c.getDeclaredMethod("getITelephony");
        m.setAccessible(true);
        ITelephony telephonyService = (ITelephony)m.invoke(tm);
        telephonyService.endCall();             
    } catch(Exception e) { e.printStackTrace(); }

    stopSelf();
}


public void onResume() {
    System.out.println("|#| **** PhoneCallService - onResume() **** |#|");

}
@Override
public void onDestroy() {
    // TODO Auto-generated method stub
    super.onDestroy();
    System.out.println("|#| **** PhoneCallService - Finishing service **** |#|");

}
}

这是我在logcat中看到的日志:

I/ActivityManager(   59): Starting activity: Intent { act=android.intent.action.CALL_PRIVILEGED dat=tel:88642536 cmp=com.android.phone/.PrivilegedOutgoingCallBroadcaster }
V/OutgoingCallBroadcaster(  121): onCreate: this = com.android.phone.OutgoingCallBroadcaster@44f70190, icicle = null
V/OutgoingCallBroadcaster(  121):  - getIntent() = Intent { act=android.intent.action.CALL_PRIVILEGED dat=tel:88642536 cmp=com.android.phone/.PrivilegedOutgoingCallBroadcaster }
V/OutgoingCallBroadcaster(  121):  - configuration = { scale=1.0 imsi=310/260 loc=en_US touch=3 keys=2/1/2 nav=3/1 orien=1 layout=34 uiMode=17 seq=3}
D/PhoneApp(  121): pulse screen lock
D/PhoneUtils(  121): checkAndCopyPhoneProviderExtras: some or all extras are missing.
V/OutgoingCallBroadcaster(  121): Broadcasting intent Intent { act=android.intent.action.NEW_OUTGOING_CALL (has extras) }.
I/System.out(  597): |#| **** PhoneCallReceiverOut - New call to: 88642536 **** |#|
I/System.out(  597): |#| **** PhoneCallReceiverOut - Se inicia el Servicio **** |#|
I/System.out(  597): |#| **** PhoneCallReceiverOut - Saliendo del Receiber **** |#|
I/System.out(  597): Service init
V/OutgoingCallReceiver(  121): doReceive: Intent { act=android.intent.action.NEW_OUTGOING_CALL (has extras) }
V/OutgoingCallReceiver(  121): CALL to 88642536 proceeding.
D/PhoneUtils(  121): checkAndCopyPhoneProviderExtras: some or all extras are missing.
I/System.out(  597): |#| **** PhoneCallService - Starting service **** |#|
I/System.out(  597): |#| **** PhoneCallService - End call in : 2 minutes ( 120000 seconds) **** |#|
V/OutgoingCallReceiver(  121): doReceive(): calling startActivity: Intent { act=android.intent.action.CALL dat=tel:88642536 flg=0x10000000 cmp=com.android.phone/.InCallScreen (has extras) }
I/ActivityManager(   59): Starting activity: Intent { act=android.intent.action.CALL dat=tel:88642536 flg=0x10000000 cmp=com.android.phone/.InCallScreen (has extras) }
D/InCallScreen(  121): onNewIntent: intent=Intent { act=android.intent.action.CALL dat=tel:88642536 flg=0x10c00000 cmp=com.android.phone/.InCallScreen (has extras) }
D/InCallScreen(  121): internalResolveIntent: action=android.intent.action.CALL
I/AudioService(   59):  AudioFocus  requestAudioFocus() from AudioFocus_For_Phone_Ring_And_Calls
D/AudioHardwareInterface(   34): setMode(IN_CALL)
D/InCallScreen(  121): onResume()...
D/PhoneApp(  121): disable status bar
D/PhoneApp(  121): StatusBarManager.DISABLE_EXPAND
D/StatusBar(   59): DISABLE_EXPAND: yes
D/InCallScreen(  121): - onResume: initial status = SUCCESS
D/InCallScreen(  121): setInCallScreenMode: NORMAL
D/InCallScreen(  121): syncWithPhoneState()...
D/PhoneUtils(  121): dumpCallState():
D/PhoneUtils(  121): - Phone: Handler{44ec0e90}, name = GSM, state = OFFHOOK
D/PhoneUtils(  121):   - FG call: DIALING isAlive true isRinging false isDialing true isIdle false hasConnections true
D/PhoneUtils(  121):   - BG call: IDLE isAlive false isRinging false isDialing false isIdle true hasConnections false
D/PhoneUtils(  121):   - RINGING call: IDLE isAlive false isRinging false isDialing false isIdle true hasConnections false
D/PhoneUtils(  121):   - hasRingingCall false hasActiveCall true hasHoldingCall false allLinesTaken false
D/PhoneUtils(  121):   - Ringer state: false
D/InCallScreen(  121): updateScreen()...
D/InCallScreen(  121): - updateScreen: updating the in-call UI...
D/PhoneApp(  121): updateWakeState: callscreen true, dialer false, speaker false...
D/PhoneApp(  121): updateWakeState: keepScreenOn = true (isRinging false, isDialing true, showingDisc false)
D/CallNotifier(  121): stopRing()... (OFFHOOK state)
D/Ringer  (  121): stopRing()...
D/Ringer  (  121): - stopRing: null mRingHandler!
D/InCallScreen(  121): onPhoneStateChanged()...
D/InCallScreen(  121): updateScreen()...
D/InCallScreen(  121): - updateScreen: updating the in-call UI...
D/PhoneApp(  121): updateWakeState: callscreen true, dialer false, speaker false...
D/PhoneApp(  121): updateWakeState: keepScreenOn = true (isRinging false, isDialing true, showingDisc false)
D/CallNotifier(  121): stopRing()... (OFFHOOK state)
D/Ringer  (  121): stopRing()...
D/Ringer  (  121): - stopRing: null mRingHandler!
D/InCallScreen(  121): onPhoneStateChanged()...
D/InCallScreen(  121): updateScreen()...
D/InCallScreen(  121): - updateScreen: updating the in-call UI...
D/PhoneApp(  121): updateWakeState: callscreen true, dialer false, speaker false...
D/PhoneApp(  121): updateWakeState: keepScreenOn = true (isRinging false, isDialing true, showingDisc false)
D/CallNotifier(  121): stopRing()... (OFFHOOK state)
D/Ringer  (  121): stopRing()...
D/Ringer  (  121): - stopRing: null mRingHandler!
D/InCallScreen(  121): onPhoneStateChanged()...
D/InCallScreen(  121): updateScreen()...
D/InCallScreen(  121): - updateScreen: updating the in-call UI...
D/PhoneApp(  121): updateWakeState: callscreen true, dialer false, speaker false...
D/PhoneApp(  121): updateWakeState: keepScreenOn = true (isRinging false, isDialing true, showingDisc false)
D/CallNotifier(  121): stopRing()... (OFFHOOK state)
D/Ringer  (  121): stopRing()...
D/Ringer  (  121): - stopRing: null mRingHandler!
D/InCallScreen(  121): onPhoneStateChanged()...
D/InCallScreen(  121): updateScreen()...
D/InCallScreen(  121): - updateScreen: updating the in-call UI...
D/PhoneApp(  121): updateWakeState: callscreen true, dialer false, speaker false...
D/PhoneApp(  121): updateWakeState: keepScreenOn = true (isRinging false, isDialing true, showingDisc false)
W/InputManagerService(   59): Starting input on non-focused client com.android.internal.view.IInputMethodClient$Stub$Proxy@44fb1e78 (uid=10000 pid=160)
D/CallNotifier(  121): stopRing()... (OFFHOOK state)
D/Ringer  (  121): stopRing()...
D/Ringer  (  121): - stopRing: null mRingHandler!
D/InCallScreen(  121): onPhoneStateChanged()...
D/InCallScreen(  121): updateScreen()...
D/InCallScreen(  121): - updateScreen: updating the in-call UI...
D/PhoneApp(  121): updateWakeState: callscreen true, dialer false, speaker false...
D/PhoneApp(  121): updateWakeState: keepScreenOn = false (isRinging false, isDialing false, showingDisc false)
W/ActivityManager(   59): Timeout of broadcast BroadcastRecord{44ffa778 android.intent.action.PHONE_STATE} - receiver=android.os.BinderProxy@4512e960
W/ActivityManager(   59): Receiver during timeout: ResolveInfo{450dc090 com.shwordfishland.calltimecontrol.PhoneCallReceiver p=0 o=0 m=0x108000}
I/Process (   59): Sending signal. PID: 597 SIG: 3
I/dalvikvm(  597): threadid=3: reacting to signal 3
I/dalvikvm(  597): Wrote stack traces to '/data/anr/traces.txt'
I/Process (   59): Sending signal. PID: 59 SIG: 3
I/dalvikvm(   59): threadid=3: reacting to signal 3
I/dalvikvm(   59): Wrote stack traces to '/data/anr/traces.txt'
I/Process (   59): Sending signal. PID: 117 SIG: 3
I/dalvikvm(  117): threadid=3: reacting to signal 3
I/dalvikvm(  117): Wrote stack traces to '/data/anr/traces.txt'
I/Process (   59): Sending signal. PID: 121 SIG: 3
I/dalvikvm(  121): threadid=3: reacting to signal 3
I/dalvikvm(  121): Wrote stack traces to '/data/anr/traces.txt'
I/Process (   59): Sending signal. PID: 160 SIG: 3
I/dalvikvm(  160): threadid=3: reacting to signal 3
I/dalvikvm(  160): Wrote stack traces to '/data/anr/traces.txt'
I/Process (   59): Sending signal. PID: 263 SIG: 3
I/dalvikvm(  263): threadid=3: reacting to signal 3
I/dalvikvm(  263): Wrote stack traces to '/data/anr/traces.txt'
I/Process (   59): Sending signal. PID: 254 SIG: 3
I/dalvikvm(  254): threadid=3: reacting to signal 3
I/dalvikvm(  254): Wrote stack traces to '/data/anr/traces.txt'
I/Process (   59): Sending signal. PID: 461 SIG: 3
I/dalvikvm(  461): threadid=3: reacting to signal 3
I/dalvikvm(  461): Wrote stack traces to '/data/anr/traces.txt'
I/Process (   59): Sending signal. PID: 132 SIG: 3
I/dalvikvm(  132): threadid=3: reacting to signal 3
I/dalvikvm(  132): Wrote stack traces to '/data/anr/traces.txt'
I/Process (   59): Sending signal. PID: 192 SIG: 3
I/dalvikvm(  192): threadid=3: reacting to signal 3
I/dalvikvm(  192): Wrote stack traces to '/data/anr/traces.txt'
I/Process (   59): Sending signal. PID: 166 SIG: 3
I/dalvikvm(  166): threadid=3: reacting to signal 3
I/dalvikvm(  166): Wrote stack traces to '/data/anr/traces.txt'
I/Process (   59): Sending signal. PID: 229 SIG: 3
I/dalvikvm(  229): threadid=3: reacting to signal 3
I/dalvikvm(  229): Wrote stack traces to '/data/anr/traces.txt'
I/Process (   59): Sending signal. PID: 219 SIG: 3
I/dalvikvm(  219): threadid=3: reacting to signal 3
I/dalvikvm(  219): Wrote stack traces to '/data/anr/traces.txt'
E/ActivityManager(   59): ANR in com.shwordfishland.calltimecontrol
E/ActivityManager(   59): Reason: Broadcast of Intent { act=android.intent.action.PHONE_STATE flg=0x20000000 cmp=com.shwordfishland.calltimecontrol/.PhoneCallReceiver (has extras) }
E/ActivityManager(   59): Load: 0.7 / 0.22 / 0.18
E/ActivityManager(   59): CPU usage from 28840ms to 86ms ago:
E/ActivityManager(   59):   system_server: 20% = 14% user + 5% kernel / faults: 1840 minor
E/ActivityManager(   59):   m.android.phone: 6% = 5% user + 1% kernel / faults: 867 minor
E/ActivityManager(   59):   adbd: 3% = 0% user + 3% kernel / faults: 1 minor
E/ActivityManager(   59):   d.process.acore: 3% = 2% user + 0% kernel / faults: 540 minor
E/ActivityManager(   59):   logcat: 0% = 0% user + 0% kernel / faults: 4 minor
E/ActivityManager(   59):   mediaserver: 0% = 0% user + 0% kernel / faults: 11 minor
E/ActivityManager(   59):   d.process.media: 0% = 0% user + 0% kernel / faults: 47 minor
E/ActivityManager(   59):   ronsoft.openwnn: 0% = 0% user + 0% kernel / faults: 30 minor
E/ActivityManager(   59):   id.defcontainer: 0% = 0% user + 0% kernel / faults: 47 minor
E/ActivityManager(   59):   qemud: 0% = 0% user + 0% kernel
E/ActivityManager(   59):   ndroid.launcher: 0% = 0% user + 0% kernel / faults: 43 minor
E/ActivityManager(   59):   m.android.email: 0% = 0% user + 0% kernel / faults: 47 minor
E/ActivityManager(   59):   .quicksearchbox: 0% = 0% user + 0% kernel / faults: 45 minor
E/ActivityManager(   59):   com.svox.pico: 0% = 0% user + 0% kernel / faults: 43 minor
E/ActivityManager(   59):   ndroid.settings: 0% = 0% user + 0% kernel / faults: 43 minor
E/ActivityManager(   59):   roid.alarmclock: 0% = 0% user + 0% kernel / faults: 43 minor
E/ActivityManager(   59):   zygote: 0% = 0% user + 0% kernel / faults: 58 minor
E/ActivityManager(   59):   servicemanager: 0% = 0% user + 0% kernel / faults: 5 minor
E/ActivityManager(   59):   rild: 0% = 0% user + 0% kernel
E/ActivityManager(   59):  +calltimecontrol: 0% = 0% user + 0% kernel
E/ActivityManager(   59):  +calltimecontrol: 0% = 0% user + 0% kernel
E/ActivityManager(   59): TOTAL: 39% = 25% user + 14% kernel + 0% softirq
I/Process (   59): Sending signal. PID: 597 SIG: 9
I/ActivityManager(   59): Process com.shwordfishland.calltimecontrol (pid 597) has died.
W/ActivityManager(   59): Scheduling restart of crashed service com.shwordfishland.calltimecontrol/.PhoneCallService in 22608ms
D/dalvikvm(   59): GC_FOR_MALLOC freed 4066 objects / 612200 bytes in 171ms
I/dalvikvm-heap(   59): Grow heap (frag case) to 6.336MB for 168632-byte allocation
D/dalvikvm(   59): GC_FOR_MALLOC freed 182 objects / 8984 bytes in 187ms
D/dalvikvm(  160): GC_EXPLICIT freed 2956 objects / 202280 bytes in 147ms
I/ActivityManager(   59): Start proc com.shwordfishland.calltimecontrol for service com.shwordfishland.calltimecontrol/.PhoneCallService: pid=604 uid=10037 gids={1015}
I/System.out(  604): Service init
I/System.out(  604): |#| **** PhoneCallService - Starting service **** |#|
I/System.out(  604): |#| **** PhoneCallService - End call in : 2 minutes ( 120000 seconds) **** |#|
W/ActivityManager(   59): Timeout executing service: ServiceRecord{450eafc8 com.shwordfishland.calltimecontrol/.PhoneCallService}
I/Process (   59): Sending signal. PID: 604 SIG: 3
I/dalvikvm(  604): threadid=3: reacting to signal 3
I/dalvikvm(  604): Wrote stack traces to '/data/anr/traces.txt'
I/Process (   59): Sending signal. PID: 59 SIG: 3
I/dalvikvm(   59): threadid=3: reacting to signal 3
I/dalvikvm(   59): Wrote stack traces to '/data/anr/traces.txt'
I/Process (   59): Sending signal. PID: 117 SIG: 3
I/dalvikvm(  117): threadid=3: reacting to signal 3
I/dalvikvm(  117): Wrote stack traces to '/data/anr/traces.txt'
I/Process (   59): Sending signal. PID: 121 SIG: 3
I/dalvikvm(  121): threadid=3: reacting to signal 3
I/dalvikvm(  121): Wrote stack traces to '/data/anr/traces.txt'
I/Process (   59): Sending signal. PID: 160 SIG: 3
I/dalvikvm(  160): threadid=3: reacting to signal 3
I/dalvikvm(  160): Wrote stack traces to '/data/anr/traces.txt'
I/Process (   59): Sending signal. PID: 263 SIG: 3
I/dalvikvm(  263): threadid=3: reacting to signal 3
I/dalvikvm(  263): Wrote stack traces to '/data/anr/traces.txt'
I/Process (   59): Sending signal. PID: 254 SIG: 3
I/dalvikvm(  254): threadid=3: reacting to signal 3
I/dalvikvm(  254): Wrote stack traces to '/data/anr/traces.txt'
I/Process (   59): Sending signal. PID: 461 SIG: 3
I/dalvikvm(  461): threadid=3: reacting to signal 3
I/dalvikvm(  461): Wrote stack traces to '/data/anr/traces.txt'
I/Process (   59): Sending signal. PID: 132 SIG: 3
I/dalvikvm(  132): threadid=3: reacting to signal 3
I/dalvikvm(  132): Wrote stack traces to '/data/anr/traces.txt'
I/Process (   59): Sending signal. PID: 192 SIG: 3
I/dalvikvm(  192): threadid=3: reacting to signal 3
I/dalvikvm(  192): Wrote stack traces to '/data/anr/traces.txt'
I/Process (   59): Sending signal. PID: 166 SIG: 3
I/dalvikvm(  166): threadid=3: reacting to signal 3
I/dalvikvm(  166): Wrote stack traces to '/data/anr/traces.txt'
I/Process (   59): Sending signal. PID: 229 SIG: 3
I/dalvikvm(  229): threadid=3: reacting to signal 3
I/dalvikvm(  229): Wrote stack traces to '/data/anr/traces.txt'
I/Process (   59): Sending signal. PID: 219 SIG: 3
I/dalvikvm(  219): threadid=3: reacting to signal 3
I/dalvikvm(  219): Wrote stack traces to '/data/anr/traces.txt'
E/ActivityManager(   59): ANR in com.shwordfishland.calltimecontrol
E/ActivityManager(   59): Reason: Executing service com.shwordfishland.calltimecontrol/.PhoneCallService
E/ActivityManager(   59): Load: 0.49 / 0.23 / 0.19
E/ActivityManager(   59): CPU usage from 44174ms to 115ms ago:
E/ActivityManager(   59):   system_server: 11% = 8% user + 3% kernel / faults: 249 minor
E/ActivityManager(   59):   m.android.phone: 4% = 3% user + 0% kernel / faults: 31 minor
E/ActivityManager(   59):   adbd: 0% = 0% user + 0% kernel
E/ActivityManager(   59):   d.process.acore: 0% = 0% user + 0% kernel / faults: 66 minor
E/ActivityManager(   59):   logcat: 0% = 0% user + 0% kernel
E/ActivityManager(   59):   d.process.media: 0% = 0% user + 0% kernel / faults: 9 minor
E/ActivityManager(   59):   id.defcontainer: 0% = 0% user + 0% kernel / faults: 9 minor
E/ActivityManager(   59):   zygote: 0% = 0% user + 0% kernel / faults: 37 minor
E/ActivityManager(   59):   m.android.email: 0% = 0% user + 0% kernel / faults: 8 minor
E/ActivityManager(   59):   ndroid.launcher: 0% = 0% user + 0% kernel / faults: 7 minor
E/ActivityManager(   59):   .quicksearchbox: 0% = 0% user + 0% kernel / faults: 8 minor
E/ActivityManager(   59):   com.svox.pico: 0% = 0% user + 0% kernel / faults: 7 minor
E/ActivityManager(   59):   ndroid.settings: 0% = 0% user + 0% kernel / faults: 7 minor
E/ActivityManager(   59):   qemud: 0% = 0% user + 0% kernel
E/ActivityManager(   59):   ronsoft.openwnn: 0% = 0% user + 0% kernel / faults: 7 minor
E/ActivityManager(   59):   roid.alarmclock: 0% = 0% user + 0% kernel / faults: 7 minor
E/ActivityManager(   59):  +calltimecontrol: 0% = 0% user + 0% kernel
E/ActivityManager(   59):  +calltimecontrol: 0% = 0% user + 0% kernel
E/ActivityManager(   59): TOTAL: 18% = 12% user + 5% kernel + 0% irq + 0% softirq
I/Process (   59): Sending signal. PID: 604 SIG: 9
I/ActivityManager(   59): Process com.shwordfishland.calltimecontrol (pid 604) has died.
W/ActivityManager(   59): Scheduling restart of crashed service com.shwordfishland.calltimecontrol/.PhoneCallService in 90432ms
D/dalvikvm(   59): GC_FOR_MALLOC freed 1819 objects / 820856 bytes in 157ms
D/CallNotifier(  121): stopRing()... (OFFHOOK state)
D/Ringer  (  121): stopRing()...
D/Ringer  (  121): - stopRing: null mRingHandler!
D/InCallScreen(  121): onPhoneStateChanged()...
D/InCallScreen(  121): updateScreen()...
D/InCallScreen(  121): - updateScreen: updating the in-call UI...
D/PhoneApp(  121): updateWakeState: callscreen true, dialer false, speaker false...
D/PhoneApp(  121): updateWakeState: keepScreenOn = true (isRinging false, isDialing false, showingDisc true)
I/AudioService(   59):  AudioFocus  abandonAudioFocus() from AudioFocus_For_Phone_Ring_And_Calls
D/CallNotifier(  121): DISCONNECT
D/CallNotifier(  121): - onDisconnect: cause = LOCAL, incoming = false, date = 1315611026140
I/ActivityManager(   59): Start proc com.shwordfishland.calltimecontrol for broadcast com.shwordfishland.calltimecontrol/.PhoneCallReceiver: pid=611 uid=10037 gids={1015}
D/CallNotifier(  121): stopRing()... (onDisconnect)
D/Ringer  (  121): stopRing()...
D/Ringer  (  121): - stopRing: null mRingHandler!
D/CallNotifier(  121): - onDisconnect(): logNumber set to: 88642536
D/CallNotifier(  121): - getPresentation(): ignoring connection's presentation: 1
D/CallNotifier(  121): - getPresentation: presentation: 1
D/InCallScreen(  121): onDisconnect:  incoming: false state: DISCONNECTED post dial state: COMPLETE, cause=LOCAL

我不确定这是最好的方法,但这是我用有限的知识做的。

非常感谢任何帮助或建议。

最好的问候。

JR

1 个答案:

答案 0 :(得分:1)

当Intent触发您的BroadcastReceiver时,系统会唤醒,直到onReceive()的{​​{1}}完成为止。当此方法完成时,系统资源将返回休眠状态,包括CPU。由于您从BroadcastReceiver启动服务,该服务将继续运行,直到CPU运行,但它会停止您的服务也将停止。为了处理这种情况,您必须在onReceive()中获取CPU唤醒锁并将其传递给服务,服务将在作业完成时释放它。希望这可以帮助!

请点击此处:Problem acquiring wake lock from broadcast receiver