当app在后台

时间:2018-02-18 14:37:59

标签: android background localization

我的Android应用必须每10秒定期向服务器发送一次位置。 它在IntentService中运行启动智能手机中定期本地化的代码;我现在用的是:

LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, MYLOCATIONREQUEST, this, Looper.getMainLooper());

如果应用程序在前台,它可以正常工作;当我的应用程序进入后台时,定期本地化继续工作,但经过一段时间(大约2分钟),它得到的坐标是错误的:我在家里坐着我的智能手机,所以我处于固定的位置(点A),并且在开始时位置是正确的,但是在2分钟之后智能手机得到一个错误的固定位置(点B),这总是相同的;我的意思是,如果我在第二天做同样的事情,当应用程序进入后台时,在2分钟后它会获得前一天的相同位置B.在某些情况下,不太经常,我注意到它得到另一个点(点C),并且在这种情况下它是固定的,即它继续得到总是点C. 当应用程序回到foregroung时,几秒钟后它再次返回正确的位置(A点)。

需要注意的是,我将日志调试'FAU_DEBUG'(见下文)放在重写方法'onLocationChanged()'中:同样在后台,每隔10秒定期给出一个位置。 此外,我现在总是使用'​​ACCESS_COARSE_LOCATION'(在Android设置中未启用FINE)。

我还注意到:

  • 当我的应用程序处于前台并且显示屏熄灭时,几分钟后它开始出现错误的位置B.
  • 当我的应用程序处于前台,并且我转向另一个应用程序(例如whastapp)并且显示器打开时,它继续获得正确的位置A直到显示器打开;当显示器熄灭时,它开始得到错误的位置B

总结一下,当应用程序进入后台并且显示屏熄灭时,它会在开始时得到正确的A点,2分钟后它会得到错误的B点(并且通常是错误的点C)。当应用程序返回前台时,它会再次获得正确的A点。

在日志下方,其中:

  • A点是:长_____ 12.4505882 - Lat = 41.8227214
  • B点是:长 _____ 12.455792 - Lat = 41.8242919

您可以在标记为“******* FAU_DEBUG *******”的日志消息中看到它们。

我试图了解可能导致错误的原因;唯一的安卓消息可以告诉我一些关于'com.google.android.location.ALARM_WAKEUP_LOCATOR已过去'的事情,但只有在它经常出现的时候,也就是当问题没有发生时。

Android智能手机有6.0(Marshmellow)。

这对我来说是一个大问题,因为我的应用程序的主要目标是本地化智能手机,当然通常显示屏关闭,应用程序进入后台。

02-18 14:53:45.758 E: readlink('/proc/self/fd/44') failed: Permission denied [fd=44]
02-18 14:53:45.758 E: warning: unable to get realpath for the library "/data/data/com.google.android.gms/app_chimera/m/00000053/n/arm64-v8a/libcronet.61.0.3163.140.so". Will use given name.
02-18 14:53:45.766 I: Cronet version: 61.0.3163.140, arch: aarch64
02-18 14:53:45.851 I: Background partial concurrent mark sweep GC freed 116052(6MB) AllocSpace objects, 92(4MB) LOS objects, 17% free, 55MB/67MB, paused 2.486ms total 215.096ms
02-18 14:53:45.918 I: Waiting for service SurfaceFlinger...
02-18 14:53:45.919 I: Waiting for service SurfaceFlinger...
02-18 14:53:45.991 I: addGeofences: geofencingRequest=GeofencingRequest[geofences=[Geofence[CIRCLE id:atn_geofence_request_id transitions:2 41.824292, 12.455792 20000m, resp=0s, dwell=-1ms, @77951352]], initialTrigger=2, tag=] intent=PendingIntent{d568a02: android.os.BinderProxy@e29e787}
02-18 14:53:45.993 I: Use last location to update newly added Geofences.
02-18 14:53:46.098 I: expired arrive. level:-1
02-18 14:53:46.098 I: during_ms:2003,period_ms:2000
02-18 14:53:46.098 I: count:184,rx_sum:1,tx_sum:2,rxBytes:85,during_ms:2003,rx_speed:42.43634548177733,tx_speed:69.39590614078881,rto:0.5
02-18 14:53:46.921 I: Waiting for service SurfaceFlinger...
02-18 14:53:46.921 I: Waiting for service SurfaceFlinger...
02-18 14:53:47.110 I: update:rxPkts:0,txPkts:0,rxBytes:0,txBytes:0
02-18 14:53:47.111 I: start expired. level:-1
02-18 14:53:47.111 I: gettimer:interval=2000
02-18 14:53:47.117 W: WAKEUP alarm trigger action = com.google.android.location.ALARM_WAKEUP_LOCATOR elapsed = 63252514

                      [ 02-18 14:53:47.142 29309:29309 W/         ]
                      Classe ' *******FAU_DEBUG*******  --- 14:53:47:140 --- LocationManager' -|||- 'onLocationChanged()' -|||- ****************************:   **Long _____12.4505882 -- Lat=41.8227214** -- Datetime=Sun Feb 18 14:53:47 GMT+01:00 2018____          -|||- Nome Thread (che invoca il Log)='main' 


                      [ 02-18 14:53:47.144 29309:29309 W/         ]
                      Classe ' *******FAU_DEBUG*******  --- 14:53:47:143 --- LocationManager' -|||- 'onLocationChanged()' -|||- ****************************:   MYLOCATION_Arg _____Location[fused 42******,12****** acc=317 et=+17h34m7s518ms]____          -|||- Nome Thread (che invoca il Log)='main' 
02-18 14:53:47.924 I: Waiting for service SurfaceFlinger...
02-18 14:53:47.924 I: Waiting for service SurfaceFlinger...
02-18 14:53:48.927 I: Waiting for service SurfaceFlinger...
02-18 14:53:48.927 I: Waiting for service SurfaceFlinger...
02-18 14:53:49.043 E: [charger_ic] temp_new :32  temp_old :31
02-18 14:53:49.043 E: Report temperature: [charger_ic] temp :32  report_threshold:1
02-18 14:53:49.116 I: update:rxPkts:0,txPkts:0,rxBytes:0,txBytes:0
02-18 14:53:49.116 I: start expired. level:-1
02-18 14:53:49.116 I: gettimer:interval=2000
02-18 14:53:49.527 I: NotificationGuideService:handle MSG_ACTIVIY_FOREGROUND, uid:10058

02-18 14:53:49.560 I:  uid:10151 pid:-2 flags:536870922 tag:WindowManager wakeup time:222333
02-18 14:53:49.582 I: NotificationGuideService:handle MSG_ACTIVIY_FOREGROUND, uid:10151                      

02-18 14:53:49.689 W: removeNotificationEntry for unknown key: 0|com.fpricoco.etip|101|null|10151
02-18 14:53:49.717 I: alloc w[1080] h[1920] format[1] usage[2816]
02-18 14:53:49.721 I: alloc succ handle[0x55941194f0] stride[1120]
02-18 14:53:49.721 I: alloc w[1080] h[1920] format[1] usage[2816]
02-18 14:53:49.728 I: alloc succ handle[0x5594013cd0] stride[1120]
02-18 14:53:49.728 I: alloc w[1080] h[1920] format[1] usage[2816]
02-18 14:53:49.733 I: alloc succ handle[0x559402d280] stride[1120]
02-18 14:53:49.753 I: Displayed com.fpricoco.etip/.Activities.BaseActivity: +174ms (total +186ms)
02-18 14:53:49.928 I: Waiting for service SurfaceFlinger...
02-18 14:53:49.928 I: Waiting for service SurfaceFlinger...
02-18 14:53:50.191 W: HwNotification updateNotifications size is zero
 02-18 14:53:50.803 I: addNotification notification pkgName=com.fpricoco.etip,isOngoing=true,isCleanable=false
02-18 14:53:50.883 I: mSecurityInputMethodService is null
02-18 14:53:50.884 I: mSecurityInputMethodService is null
02-18 14:53:50.884 I: mSecurityInputMethodService is null
02-18 14:53:51.121 I: update:rxPkts:0,txPkts:0,rxBytes:0,txBytes:0
02-18 14:53:51.122 I: start expired. level:-1
02-18 14:53:51.122 I: gettimer:interval=2000
02-18 14:53:51.180 I: Waiting for service SurfaceFlinger...
02-18 14:53:51.180 I: Waiting for service SurfaceFlinger...
02-18 14:53:51.305 W: HwNotification updateNotifications size is zero
02-18 14:53:51.769 E: updateConfiguration freq=2427 BSSID=90:35:6e:e7:a2:88 RSSI=-68 "Vodafone-FAU"WPA_PSK
02-18 14:53:51.780 I: spd good count:0, add sc:0.0, rate:1.0
02-18 14:53:51.781 I: current mHighDataFlowRate = 1.0
02-18 14:53:51.781 I: POta txb txg rxg:0, 2, 0. Lr =0% Totpkt=2
02-18 14:53:51.782 I: ######### CMD_QUERY_PKTS ########
02-18 14:53:51.783 I: postEventFromNative: msg=100,arg1=0,arg2=9
02-18 14:53:51.783 W: poll before: g_monitor_fd =131
02-18 14:53:51.783 I: rtt=400,tcp_tx_pkts=75574,tcp_rx_pkts=140276
02-18 14:53:51.784 I: PTcp RTT:0, rtt pkt=0, tcp_rx=1, tcp_tx=2, tcp_reTran=0, rtRate=0
02-18 14:53:51.784 I: rs ota tcp lr rttvb bad: false, false, false, false, false; rsth:-75
02-18 14:53:51.785 I:  pkt chk not bad, reset sc to 0.
02-18 14:53:51.794 I: QOS_level:5(5),wifi-link;use signalLvl:5;RAT:4G
02-18 14:53:52.112 I: expired arrive. level:-1
02-18 14:53:52.112 I: during_ms:2005,period_ms:2000
02-18 14:53:52.112 I: count:187,rx_sum:0,tx_sum:0,rxBytes:0,during_ms:2005,rx_speed:0.0,tx_speed:0.0,rto:0.0
02-18 14:53:52.146 W: WAKEUP alarm trigger action = com.google.android.location.ALARM_WAKEUP_LOCATOR elapsed = 63257542
02-18 14:53:52.173 W: shouldBlockLocation running ...
02-18 14:53:52.173 I: shouldBlockLocation  ret:false
02-18 14:53:52.180 I: Waiting for service SurfaceFlinger...
02-18 14:53:52.180 W: shouldBlockLocation running ...
02-18 14:53:52.181 I: Waiting for service SurfaceFlinger...
02-18 14:53:52.181 I: shouldBlockLocation  ret:false


                02-18 14:53:53.125 I: update:rxPkts:3,txPkts:3,rxBytes:174,txBytes:177
02-18 14:53:53.125 I: start expired. level:-1
02-18 14:53:53.126 I: gettimer:interval=2000
02-18 14:53:53.183 I: Waiting for service SurfaceFlinger...
02-18 14:53:53.183 I: Waiting for service SurfaceFlinger...
02-18 14:53:53.894 I: mSecurityInputMethodService is null
02-18 14:53:54.186 I: Waiting for service SurfaceFlinger...
02-18 14:53:54.186 I: Waiting for service SurfaceFlinger...
02-18 14:53:54.682 I: action:android.os.action.POWER_SAVE_TEMP_WHITELIST_CHANGED, mPermissionType:0
02-18 14:53:55.072 I: action:com.google.android.gms.gcm.ACTION_SCHEDULE, mPermissionType:0
02-18 14:53:55.129 I: update:rxPkts:0,txPkts:0,rxBytes:0,txBytes:0
02-18 14:53:55.129 I: start expired. level:-1
02-18 14:53:55.129 I: gettimer:interval=2000
02-18 14:53:55.186 I: Waiting for service SurfaceFlinger...
02-18 14:53:55.187 I: Waiting for service SurfaceFlinger...
02-18 14:53:56.442 I: Waiting for service SurfaceFlinger...
02-18 14:53:56.442 I: Waiting for service SurfaceFlinger...
02-18 14:53:57.135 I: update:rxPkts:0,txPkts:0,rxBytes:0,txBytes:0
02-18 14:53:57.135 I: start expired. level:-1
02-18 14:53:57.135 I: gettimer:interval=2000
02-18 14:53:57.162 W: WAKEUP alarm trigger action = com.google.android.location.ALARM_WAKEUP_LOCATOR elapsed = 63262559

                      [ 02-18 14:53:57.202 29309:29309 W/         ]
                      Classe ' *******FAU_DEBUG*******  --- 14:53:57:201 --- LocationManager' -|||- 'onLocationChanged()' -|||- ****************************:   Long _____12.4505882 -- Lat=41.8227214 -- Datetime=Sun Feb 18 14:53:57 GMT+01:00 2018____          -|||- Nome Thread (che invoca il Log)='main' 


                      [ 02-18 14:53:57.205 29309:29309 W/         ]
                      Classe ' *******FAU_DEBUG*******  --- 14:53:57:204 --- LocationManager' -|||- 'onLocationChanged()' -|||- ****************************:   MYLOCATION_Arg _____Location[fused 42******,12****** acc=328 et=+17h34m17s566ms]____          -|||- Nome Thread (che invoca il Log)='main' 
02-18 14:53:57.224 I: Successfully inserted 1 locations
02-18 14:53:57.324 E: getTempInfo error: null, 0
02-18 14:53:57.324 E: getTempInfo error: null, 0
02-18 14:53:57.324 E: getTempInfo error: null, 0
02-18 14:53:57.324 E: getTempInfo error: null, 0
02-18 14:53:57.324 E: getTempInfo error: null, 0
02-18 14:53:57.340 E: getTempInfo error: null, 0
02-18 14:53:57.340 E: getTempInfo error: null, 0
02-18 14:53:57.340 E: getTempInfo error: null, 0
02-18 14:53:57.340 E: getTempInfo error: null, 0
02-18 14:53:57.340 E: getTempInfo error: null, 0
02-18 14:53:57.347 W: writeLogFile > 10240 ,tagTempAlarm
02-18 14:53:57.445 I: Waiting for service SurfaceFlinger...
02-18 14:53:57.446 I: Waiting for service SurfaceFlinger...
02-18 14:53:58.129 I: expired arrive. level:-1
02-18 14:53:58.129 I: during_ms:2006,period_ms:2000
02-18 14:53:58.130 I: count:190,rx_sum:0,tx_sum:0,rxBytes:0,during_ms:2006,rx_speed:0.0,tx_speed:0.0,rto:0.0
02-18 14:53:58.449 I: Waiting for service SurfaceFlinger...
02-18 14:53:58.449 I: Waiting for service SurfaceFlinger...
02-18 14:53:59.141 I: update:rxPkts:0,txPkts:0,rxBytes:0,txBytes:0
02-18 14:53:59.141 I: start expired. level:-1
02-18 14:53:59.141 I: gettimer:interval=2000
02-18 14:53:59.454 I: Waiting for service SurfaceFlinger...
02-18 14:53:59.454 I: Waiting for service SurfaceFlinger...
02-18 14:53:59.783 E: updateConfiguration freq=2427 BSSID=90:35:6e:e7:a2:88 RSSI=-68 "Vodafone-FAU"WPA_PSK
02-18 14:53:59.792 I: spd good count:0, add sc:0.0, rate:1.0
02-18 14:53:59.793 I: current mHighDataFlowRate = 1.0
02-18 14:53:59.794 I: POta txb txg rxg:0, 5, 0. Lr =0% Totpkt=5
02-18 14:53:59.795 I: ######### CMD_QUERY_PKTS ########
02-18 14:53:59.795 I: postEventFromNative: msg=100,arg1=0,arg2=9
02-18 14:53:59.796 W: poll before: g_monitor_fd =131
02-18 14:53:59.796 I: rtt=800,tcp_tx_pkts=75577,tcp_rx_pkts=140279
02-18 14:53:59.798 I: PTcp RTT:0, rtt pkt=0, tcp_rx=3, tcp_tx=3, tcp_reTran=0, rtRate=0
02-18 14:53:59.799 I: rs ota tcp lr rttvb bad: false, false, false, false, false; rsth:-75
02-18 14:53:59.799 I:  pkt chk not bad, reset sc to 0.
02-18 14:53:59.805 I: QOS_level:5(5),wifi-link;use signalLvl:5;RAT:4G
02-18 14:54:00.456 I: Waiting for service SurfaceFlinger...
02-18 14:54:00.456 I: Waiting for service SurfaceFlinger...
02-18 14:54:00.829 I: NotificationGuideService:handle MSG_ACTIVIY_FOREGROUND, uid:10058
02-18 14:54:00.863 I:  uid:10151 pid:-2 flags:536870922 tag:WindowManager wakeup time:233482
02-18 14:54:00.880 I: NotificationGuideService:handle MSG_ACTIVIY_FOREGROUND, uid:10151
02-18 14:54:00.978 W: removeNotificationEntry for unknown key: 0|com.fpricoco.etip|101|null|10151
02-18 14:54:01.003 I: alloc w[1080] h[1920] format[1] usage[2816]
02-18 14:54:01.007 I: alloc succ handle[0x559402d280] stride[1120]
02-18 14:54:01.008 I: alloc w[1080] h[1920] format[1] usage[2816]
02-18 14:54:01.015 I: alloc succ handle[0x5594013cd0] stride[1120]
02-18 14:54:01.015 I: alloc w[1080] h[1920] format[1] usage[2816]
02-18 14:54:01.021 I: alloc succ handle[0x55941194f0] stride[1120]
02-18 14:54:01.038 I: Displayed com.fpricoco.etip/.Activities.BaseActivity: +161ms (total +174ms)
02-18 14:54:01.143 I: update:rxPkts:0,txPkts:0,rxBytes:0,txBytes:0
02-18 14:54:01.143 I: start expired. level:-1
02-18 14:54:01.143 I: gettimer:interval=2000
02-18 14:54:01.479 W: HwNotification updateNotifications size is zero
02-18 14:54:01.711 I: Waiting for service SurfaceFlinger...
02-18 14:54:01.711 I: Waiting for service SurfaceFlinger...
                      02-18 14:54:02.090 I: addNotification notification pkgName=com.fpricoco.etip,isOngoing=true,isCleanable=false
02-18 14:54:02.168 I: mSecurityInputMethodService is null
02-18 14:54:02.170 I: mSecurityInputMethodService is null
02-18 14:54:02.171 I: mSecurityInputMethodService is null
02-18 14:54:02.206 W: WAKEUP alarm trigger action = com.google.android.location.ALARM_WAKEUP_LOCATOR elapsed = 63267604
02-18 14:54:02.209 I: receiver action = android.intent.action.TIME_TICK
02-18 14:54:02.212 I: Model  onReceive intent=Intent { act=android.intent.action.TIME_TICK flg=0x50000014 (has extras) }
02-18 14:54:02.212 I: Model  onReceive user=UserHandle{0}
02-18 14:54:02.218 I: onTimeChanged
02-18 14:54:02.224 I: CityTimeView CityTimeView mCurrentViewMode = 42001
02-18 14:54:02.225 W: onWeatherChange : displayInfo is null!
02-18 14:54:02.225 I: WidgetUtils trasnslateImageResource, resId is 2130837801 isLight =false
02-18 14:54:02.226 I: WidgetUtils trasnslateImageResource, resId is 2130837801 isLight =false
02-18 14:54:02.226 I: WidgetUtils trasnslateImageResource, resId is 2130837803 isLight =false
02-18 14:54:02.232 W: shouldBlockLocation running ...
02-18 14:54:02.233 I: shouldBlockLocation  ret:false
02-18 14:54:02.240 W: shouldBlockLocation running ...
02-18 14:54:02.240 I: shouldBlockLocation  ret:false
02-18 14:54:02.251 I: CityTimeFormatView CityTimeFormatView setTimeFormat is24Hour=true,timeFormat=
02-18 14:54:02.591 W: HwNotification updateNotifications size is zero
02-18 14:54:02.713 I: Waiting for service SurfaceFlinger...
02-18 14:54:02.714 I: Waiting for service SurfaceFlinger...
02-18 14:54:03.147 I: update:rxPkts:0,txPkts:0,rxBytes:0,txBytes:0
02-18 14:54:03.147 I: start expired. level:-1
02-18 14:54:03.147 I: gettimer:interval=2000
02-18 14:54:03.716 I: Waiting for service SurfaceFlinger...
02-18 14:54:03.716 I: Waiting for service SurfaceFlinger...
02-18 14:54:04.143 I: expired arrive. level:-1
02-18 14:54:04.143 I: during_ms:2004,period_ms:2000
02-18 14:54:04.143 I: count:193,rx_sum:0,tx_sum:0,rxBytes:0,during_ms:2004,rx_speed:0.0,tx_speed:0.0,rto:0.0
02-18 14:54:04.719 I: Waiting for service SurfaceFlinger...
02-18 14:54:04.719 I: Waiting for service SurfaceFlinger...
02-18 14:54:04.857 I: onSignal: mSubId=0,currDataSubID=0
02-18 14:54:04.857 I: received cell-signal:5
02-18 14:54:04.857 I: action:android.intent.action.SIG_STR, mPermissionType:0
02-18 14:54:04.867 I: subId:0 phoneType:1 networktype:13 targetClass:3 masterLevel:4 slaveLevel:-1
02-18 14:54:05.150 I: update:rxPkts:0,txPkts:0,rxBytes:0,txBytes:0
02-18 14:54:05.151 I: start expired. level:-1
02-18 14:54:05.151 I: gettimer:interval=2000
02-18 14:54:05.177 I: mSecurityInputMethodService is null
02-18 14:54:05.722 I: Waiting for service SurfaceFlinger...
02-18 14:54:05.722 I: Waiting for service SurfaceFlinger...
02-18 14:54:06.978 I: Waiting for service SurfaceFlinger...
02-18 14:54:06.978 I: Waiting for service SurfaceFlinger...
02-18 14:54:07.156 I: update:rxPkts:0,txPkts:0,rxBytes:0,txBytes:0
02-18 14:54:07.156 I: start expired. level:-1
02-18 14:54:07.156 I: gettimer:interval=2000
02-18 14:54:07.230 W: WAKEUP alarm trigger action = com.google.android.location.ALARM_WAKEUP_LOCATOR elapsed = 63272627

                      [ 02-18 14:54:07.250 29309:29309 W/         ]
                      Classe ' *******FAU_DEBUG*******  --- 14:54:07:249 --- LocationManager' -|||- 'onLocationChanged()' -|||- ****************************:   Long _____12.455792 -- Lat=41.8242919 -- Datetime=Sun Feb 18 14:54:07 GMT+01:00 2018____          -|||- Nome Thread (che invoca il Log)='main' 


                      [ 02-18 14:54:07.252 29309:29309 W/         ]
                      Classe ' *******FAU_DEBUG*******  --- 14:54:07:251 --- LocationManager' -|||- 'onLocationChanged()' -|||- ****************************:   MYLOCATION_Arg _____Location[fused 42******,12****** acc=700 et=+17h34m27s628ms]____          -|||- Nome Thread (che invoca il Log)='main' 
02-18 14:54:07.788 E: updateConfiguration freq=2427 BSSID=90:35:6e:e7:a2:88 RSSI=-67 "Vodafone-FAU"WPA_PSK
02-18 14:54:07.798 I: spd good count:0, add sc:0.0, rate:1.0
02-18 14:54:07.798 I: current mHighDataFlowRate = 1.0
02-18 14:54:07.798 I: POta txb txg rxg:0, 2, 0. Lr =0% Totpkt=2
02-18 14:54:07.798 I: ######### CMD_QUERY_PKTS ########
02-18 14:54:07.799 I: postEventFromNative: msg=100,arg1=0,arg2=9
02-18 14:54:07.799 W: poll before: g_monitor_fd =131
02-18 14:54:07.799 I: action:android.net.conn.DATA_ACTIVITY_CHANGE, mPermissionType:0
02-18 14:54:07.799 I: rtt=800,tcp_tx_pkts=75577,tcp_rx_pkts=140279
02-18 14:54:07.801 I: PTcp RTT:0, rtt pkt=0, tcp_rx=0, tcp_tx=0, tcp_reTran=0, rtRate=0
02-18 14:54:07.802 I: rs ota tcp lr rttvb bad: false, false, false, false, false; rsth:-75
02-18 14:54:07.802 I:  pkt chk not bad, reset sc to 0.
02-18 14:54:07.806 I: QOS_level:5(5),wifi-link;use signalLvl:5;RAT:4G

0 个答案:

没有答案