前台服务意外停止

时间:2015-08-14 16:59:29

标签: java android

我正在android中创建一个长期运行的前台服务。我的服务运行一段时间然后意外停止。我的服务几乎在其工作的每一步都记录信息。下面是我的服务停止的最后一次日志之后的logcat(第一个详细条目是我的服务创建的最后一个日志):

<script src="https://maps.googleapis.com/maps/api/js?libraries=geometry"></script>
<div id="map" style="border: 2px solid #3872ac;"></div>

我的服务在我的Activity的onStop方法中开始:

08-14 01:21:09.232 V/Screen Checking(30000): Bitmaps created sameAs check should be happening now
08-14 01:21:09.592 D/WifiStateMachine(  845): handleMessage: E msg.what=131155
08-14 01:21:09.592 D/WifiStateMachine(  845): processMsg: ConnectedState
08-14 01:21:09.592 D/WifiStateMachine(  845): processMsg: L2ConnectedState
08-14 01:21:09.592 D/WifiNative-wlan0(  845): doString: SIGNAL_POLL
08-14 01:21:09.602 D/WifiStateMachine(  845): handleMessage: X
08-14 01:21:09.912 I/Vold    (  391): [LGE][VOLD][NetlinkHandler.cpp][onEvent()] subsys:cpu, action:0
08-14 01:21:09.932 D/BubblePopupHelper( 1155): isShowingBubblePopup : false
08-14 01:21:10.662 I/ThermalEngine(  412): Sensor:pa_therm0:39000 mC
08-14 01:21:10.722 D/libc    (  396): _dns_getaddrinfo: iptype =1
08-14 01:21:10.732 D/libc    (  396): _dns_getaddrinfo: query_ipv4=1, query_ipv6=0
08-14 01:21:10.992 E/Parcel  (  466): Reading a NULL string not supported here.
08-14 01:21:10.992 E/Parcel  (  466): Reading a NULL string not supported here.
08-14 01:21:10.992 E/Parcel  (  466): Reading a NULL string not supported here.
08-14 01:21:10.992 E/Parcel  (  466): Reading a NULL string not supported here.
08-14 01:21:11.002 D/PhoneApp( 1479): getIsInUseVoLTE : false
08-14 01:21:11.012 D/PhoneApp( 1479): getIsInUseVoLTE : false
08-14 01:21:11.022 V/LGATCMDService( 1247): onSignalStrengthsChanged signalStrength=SignalStrength: 99 0 -93 -115 -88 -75 3 99 2147483647 2147483647 2147483647 2147483647 2147483647 cdma 8 level=4
08-14 01:21:11.022 D/PhoneApp( 1479): getIsInUseVoLTE : false
08-14 01:21:11.032 D/PhoneApp( 1479): getIsInUseVoLTE : false
08-14 01:21:11.042 D/PhoneApp( 1479): getIsInUseVoLTE : false
08-14 01:21:11.042 V/LGATCMDService( 1247): broadcastRssiInfo() - Start RSSI : -93 ECIO : -115
08-14 01:21:11.062 V/TelephonyAutoProfiling(31998): [getValue] FEATURE key : lgu_lte_single_device, value : null
08-14 01:21:11.062 D/BubblePopupHelper( 1155): isShowingBubblePopup : false
08-14 01:21:11.062 D/PhoneApp( 1479): getIsInUseVoLTE : false
08-14 01:21:11.062 D/PhoneInterfaceManager( 1479): [PhoneIntfMgr] sigLevel = 4
08-14 01:21:11.062 D/PhoneApp( 1479): getIsInUseVoLTE : false
08-14 01:21:11.102 I/Vold    (  391): [LGE][VOLD][NetlinkHandler.cpp][onEvent()] subsys:cpu, action:0
08-14 01:21:11.312 I/Vold    (  391): [LGE][VOLD][NetlinkHandler.cpp][onEvent()] subsys:cpu, action:0
08-14 01:21:11.902 V/AudioFlinger(  405): Audio hardware entering standby, mixer 0xb5196008, suspend count 0
08-14 01:21:11.902 V/audio_hw_primary(  405): out_standby: enter: usecase(0: deep-buffer-playback)
08-14 01:21:12.192 V/audio_hw_primary(  405): stop_output_stream: enter: usecase(0: deep-buffer-playback)
08-14 01:21:12.192 V/audio_hw_primary(  405): disable_audio_route: enter: usecase(0)
08-14 01:21:12.192 V/audio_hw_primary(  405): disable_audio_route: reset mixer path: deep-buffer-playback
08-14 01:21:12.192 V/audio_hw_primary(  405): disable_audio_route: exit
08-14 01:21:12.192 D/hardware_info(  405): hw_info_append_hw_type : device_name = speaker
08-14 01:21:12.192 V/audio_hw_primary(  405): disable_snd_device: snd_device(2: speaker)
08-14 01:21:12.212 V/audio_hw_primary(  405): stop_output_stream: exit: status(0)
08-14 01:21:12.212 V/audio_hw_primary(  405): out_standby: exit
08-14 01:21:12.212 V/AudioFlinger(  405): releaseWakeLock_l() AudioOut_2
08-14 01:21:12.212 V/AudioFlinger(  405): thread 0xb5196008 type 0 TID 663 going to sleep
08-14 01:21:12.602 D/WifiStateMachine(  845): handleMessage: E msg.what=131155
08-14 01:21:12.602 D/WifiStateMachine(  845): processMsg: ConnectedState
08-14 01:21:12.602 D/WifiStateMachine(  845): processMsg: L2ConnectedState
08-14 01:21:12.602 D/WifiNative-wlan0(  845): doString: SIGNAL_POLL
08-14 01:21:12.632 D/WifiStateMachine(  845): handleMessage: X
08-14 01:21:12.952 D/BubblePopupHelper( 1155): isShowingBubblePopup : false
08-14 01:21:13.952 D/BubblePopupHelper( 1155): isShowingBubblePopup : false
08-14 01:21:15.642 D/WifiStateMachine(  845): handleMessage: E msg.what=131155
08-14 01:21:15.642 D/WifiStateMachine(  845): processMsg: ConnectedState
08-14 01:21:15.642 D/WifiStateMachine(  845): processMsg: L2ConnectedState
08-14 01:21:15.642 D/WifiNative-wlan0(  845): doString: SIGNAL_POLL
08-14 01:21:15.662 D/WifiStateMachine(  845): handleMessage: X
08-14 01:21:15.662 I/ThermalEngine(  412): Sensor:pa_therm0:39000 mC
08-14 01:21:15.962 D/BubblePopupHelper( 1155): isShowingBubblePopup : false
08-14 01:21:16.972 D/BubblePopupHelper( 1155): isShowingBubblePopup : false
08-14 01:21:18.032 I/LiveRailSDK-101(29678): LiveRail init SDK version 2.4.0
08-14 01:21:18.032 V/LiveRailSDK-101(29678): Adapters not included
08-14 01:21:18.032 I/LiveRailSDK-101(29678): >> setDebug(false)
08-14 01:21:18.032 I/LiveRailSDK-101(29678): AdView attached to window
08-14 01:21:18.032 I/LiveRailSDK-101(29678): >> initAd()
08-14 01:21:18.042 V/LiveRailSDK-101(29678): cleanup
08-14 01:21:18.062 V/LiveRailSDK-101(29678): onSizeChanged() w=800 h=480 from oldw=0 oldh=0
08-14 01:21:18.092 V/LiveRailSDK-101(29678): Ingest Run-time Parameters
08-14 01:21:18.092 V/LiveRailSDK-101(29678): Found wifi connection LR_CONNECTIONTYPE=2
08-14 01:21:18.102 D/LiveRailSDK-101(29678): Created new SLOT based inventory pod
08-14 01:21:18.102 D/LiveRailSDK-101(29678): Pod position set to: 1
08-14 01:21:18.102 I/LiveRailSDK-101(29678): Instantiated new inventory pod slot:com.liverail.library.inventory.c@42ff57a8
08-14 01:21:18.112 V/LiveRailSDK-101(29678): Delivery url=http://ad4.liverail.com/
08-14 01:21:18.112 V/LiveRailSDK-101(29678): CookieStore contains 312 cookies.
08-14 01:21:18.112 V/LiveRailSDK-101(29678): Delivery timeout=10000 user-agent: Mozilla/5.0 (Linux; Android; Device) LiveRailSDK/2.4.0 (AB/com.juteralabs.perktv;AV/2.6.2;BV/65)
08-14 01:21:18.112 D/LiveRailSDK-101(29678): Delivery Run-time Parameters:
08-14 01:21:18.112 D/LiveRailSDK-101(29678):    LR_ADMAP=in::0
08-14 01:21:18.112 D/LiveRailSDK-101(29678):    LR_ADTYPE=3
08-14 01:21:18.112 D/LiveRailSDK-101(29678):    LR_ADUNIT=in
08-14 01:21:18.112 D/LiveRailSDK-101(29678):    LR_APPBUILD=65
08-14 01:21:18.112 D/LiveRailSDK-101(29678):    LR_APPNAME=Perk TV
08-14 01:21:18.112 D/LiveRailSDK-101(29678):    LR_APPVERS=2.6.2
08-14 01:21:18.112 D/LiveRailSDK-101(29678):    LR_BUNDLE=com.juteralabs.perktv
08-14 01:21:18.112 D/LiveRailSDK-101(29678):    LR_CARRIER=Chameleon
08-14 01:21:18.112 D/LiveRailSDK-101(29678):    LR_CONNECTIONTYPE=2
08-14 01:21:18.112 D/LiveRailSDK-101(29678):    LR_DEVICEID=6B37D6B834B51A08AC72F06522849AEA72362D72
08-14 01:21:18.112 D/LiveRailSDK-101(29678):    LR_DURATION=33
08-14 01:21:18.112 D/LiveRailSDK-101(29678):    LR_FORMAT=video/mp4;video/3gpp;video/webm
08-14 01:21:18.112 D/LiveRailSDK-101(29678):    LR_HEIGHT=480
08-14 01:21:18.112 D/LiveRailSDK-101(29678):    LR_IDFA=ae34a5b4-ed8a-4d82-8522-60059042ba4a
08-14 01:21:18.112 D/LiveRailSDK-101(29678):    LR_IDFA_FLAG=1
08-14 01:21:18.112 D/LiveRailSDK-101(29678):    LR_MAKE=LGE
08-14 01:21:18.112 D/LiveRailSDK-101(29678):    LR_MODEL=LGLS620
08-14 01:21:18.112 D/LiveRailSDK-101(29678):    LR_MUTED=1
08-14 01:21:18.112 D/LiveRailSDK-101(29678):    LR_OS=Android
08-14 01:21:18.112 D/LiveRailSDK-101(29678):    LR_OSVERS=4.4.2
08-14 01:21:18.112 D/LiveRailSDK-101(29678):    LR_POD_CURRENT=1
08-14 01:21:18.112 D/LiveRailSDK-101(29678):    LR_PUBLISHER_ID=13955
08-14 01:21:18.112 D/LiveRailSDK-101(29678):    LR_SCHEMA=liverail
08-14 01:21:18.112 D/LiveRailSDK-101(29678):    LR_SDK=android
08-14 01:21:18.112 D/LiveRailSDK-101(29678):    LR_SDK_VERSION=2.4.0
08-14 01:21:18.112 D/LiveRailSDK-101(29678):    LR_TAGS=8675307,livetv
08-14 01:21:18.112 D/LiveRailSDK-101(29678):    LR_VERTICALS=
08-14 01:21:18.112 D/LiveRailSDK-101(29678):    LR_VIDEO_POSITION=0
08-14 01:21:18.112 D/LiveRailSDK-101(29678):    LR_VIEWABLE=1
08-14 01:21:18.112 D/LiveRailSDK-101(29678):    LR_WIDTH=800
08-14 01:21:18.112 D/LiveRailSDK-101(29678): AdManager specific parameters:
08-14 01:21:18.112 D/LiveRailSDK-101(29678): layout(width=800 height=480) volume=0/15

以下是我服务中的一些代码:

 @Override
protected void onStop() {
    super.onStop();
    mServiceIntent = new Intent(this, Scan.class);
    this.startService(mServiceIntent);
    Log.v("MainActivity", "onStop called startService foregroundService should be starting");

我的活动的onDestroy方法在相关的情况下调用stopService。如何阻止我的服务停止这样?另外,您对如何使我的代码更具资源效率或您认为我应该做出的任何改进有任何建议。

2 个答案:

答案 0 :(得分:1)

为什么要在Activities onDestroy方法中停止前台服务?如果服务是在onStop中启动的,那么在活动生命周期中调用的下一个服务将是onDestory,因此很快就会停止服务。

删除在您的活动onDestroy中停止服务的代码。

您应该删除服务中的睡眠和循环,并使用具有延迟启动的处理程序。在处理程序代码的末尾,再次使用另一个延迟启动处理程序。如果搜索应该变为false,我看不到在哪里,你可以从处理程序中删除runnable。

答案 1 :(得分:0)

我的猜测是问题来自你调用startInForeground方法的地方。在onStartCommand方法中调用该方法。

文件说

  

已启动的服务可以使用startForeground(int,Notification)API将服务置于前台状态,系统认为该服务是用户主动了解的内容,因此在内存不足时不会成为查杀的候选者。 (从理论上讲,服务在当前前台应用程序的极端内存压力下被杀死仍然是可能的,但实际上这不应该是一个问题。)

关注Apple iOS Device logging了解详情。另请查看the doc link

的答案

在您调用startInForeground方法的地方,您的服务尚未启动。正在创建。

相关问题