简体   繁体   English

Phonegap应用程序在背景中死亡,同时收集位置

[英]Phonegap app dies in background while collecting location

I have an app built in PhoneGap that makes use of navigator.geolocation calls to track the coordinates of the mobile device. 我有一个内置在PhoneGap中的应用程序,它使用navigator.geolocation调用来跟踪移动设备的坐标。 The user is in control of beginning the tracking as well as ending it. 用户可以控制开始跟踪以及结束跟踪。 The app was built to receive coordinate updates while in the background. 该应用程序的构建是为了在后台接收坐标更新。 The app is released for both Android and iOS devices. 该应用程序适用于Android和iOS设备。

The Android version seems to be prone to crashing while it is in the background. Android版本似乎在后台崩溃时容易崩溃。 On some phones it does fine but on a lot of them, the app will simply die while it's supposed to be collecting coordinate data in the background. 在一些手机上它确实没问题,但是在很多手机上,应用程序只会在它应该在后台收集坐标数据时死掉。 I have posted a LogCat log below. 我在下面发布了一个LogCat日志。 It seems a WIN DEATH occurs on the CCWalkerActivity shortly after Activity Manager calls "No longer want" on the process (both are bolded below). Activity管理器在进程上调用“不再需要”之后不久, CCWalkerActivity就会出现WIN DEATH(两者都在下面加粗)。 However, I can't determine why this is happening and why it is happening so frequently. 但是,我无法确定为什么会发生这种情况以及为什么会这么频繁发生。

Is this a problem with Phonegap? 这是Phonegap的问题吗? Would creating a plugin that could the process a foreground service (using startForeground() ) be beneficial? 创建一个可以使进程成为前台服务(使用startForeground() )的插件会有益吗?

10-19 14:50:12.439 D/dalvikvm(  496): GC_CONCURRENT freed 1917K, 28% free 12417K/17031K, external 11622K/13670K, paused 12ms+10ms
10-19 14:50:13.040 D/CordovaLog( 6275): isGPSEnabled succeeded, accuracy: 12
10-19 14:50:13.040 D/CordovaLog( 6275): file:///android_asset/www/lib.js: Line 24 : isGPSEnabled succeeded, accuracy: 12
10-19 14:50:13.040 I/Web Console( 6275): isGPSEnabled succeeded, accuracy: 12 at file:///android_asset/www/lib.js:24
10-19 14:50:13.072 D/CordovaLog( 6275): collectLocationData success: 12
10-19 14:50:13.072 D/CordovaLog( 6275): file:///android_asset/www/lib.js: Line 24 : collectLocationData success: 12
10-19 14:50:13.072 I/Web Console( 6275): collectLocationData success: 12 at file:///android_asset/www/lib.js:24
10-19 14:50:14.072 D/WifiLocator(  976): Too many no-location APs. Will not compute a location nor go to the server. hasLocation=0 noLocation=0 cacheMiss=0
10-19 14:50:14.072 D/CellLocator(  976): Found cell location: Position [redacted]
10-19 14:50:14.072 D/androidNlpServiceThread(  976): reporting Location[mProvider=network,mTime=1350672614078,mLatitude=40.8390777,mLongitude=-73.6949326,mHasAltitude=false,mAltitude=0.0,mHasSpeed=false,mSpeed=0.0,mHasBearing=false,mBearing=0.0,mHasAccuracy=true,mAccuracy=1123.0,mExtras=Bundle[{networkLocationSource=cached, networkLocationType=cell}]]
10-19 14:50:14.087 D/libgps  (  496): GpsInterface_inject_location( 40.839078, -73.694933, 1123.000 )
10-19 14:50:14.087 D/libgps  (  496): MPDINJPOS_REQ msg id 12015
10-19 14:50:14.087 D/ClientReporter(  976): reported location
10-19 14:50:14.095 D/CordovaLog( 6275): collectLocationData success: 1123
10-19 14:50:14.095 D/CordovaLog( 6275): file:///android_asset/www/lib.js: Line 24 : collectLocationData success: 1123
10-19 14:50:14.095 I/Web Console( 6275): collectLocationData success: 1123 at file:///android_asset/www/lib.js:24
10-19 14:50:14.118 D/androidNlpServiceThread(  976): adding listener com.google.android.location.internal.client.NetworkLocationClient$1@40552710 with period 45
10-19 14:50:14.118 D/androidNetworkLocationListeners(  976): Still have listener com.google.android.location.internal.client.NetworkLocationClient$1@40552710
10-19 14:50:14.118 I/ActivityManager(  496): No longer want com.CCtracks.CCWalker (pid 6275): hidden #21
10-19 14:50:14.126 D/WifiLocator(  976): Too many no-location APs. Will not compute a location nor go to the server. hasLocation=0 noLocation=0 cacheMiss=0
10-19 14:50:14.126 D/CellLocator(  976): Found cell location: Position [redacted]
10-19 14:50:14.126 D/androidNlpServiceThread(  976): reporting Location[mProvider=network,mTime=1350672614137,mLatitude=40.8390777,mLongitude=-73.6949326,mHasAltitude=false,mAltitude=0.0,mHasSpeed=false,mSpeed=0.0,mHasBearing=false,mBearing=0.0,mHasAccuracy=true,mAccuracy=1123.0,mExtras=Bundle[{networkLocationSource=cached, networkLocationType=cell}]]
10-19 14:50:14.134 D/ClientReporter(  976): reported location
10-19 14:50:14.204 I/WindowManager(  496): WIN DEATH: Window{405a97d0 com.CCtracks.CCWalker/com.CCtracks.CCWalker.CCWalkerActivity paused=false}
10-19 14:50:14.228 D/androidNlpServiceThread(  976): adding listener com.google.android.location.internal.client.NetworkLocationClient$1@40552710 with period 86400
10-19 14:50:14.228 D/androidNetworkLocationListeners(  976): Still have listener com.google.android.location.internal.client.NetworkLocationClient$1@40552710
10-19 14:50:14.236 D/WifiLocator(  976): Too many no-location APs. Will not compute a location nor go to the server. hasLocation=0 noLocation=0 cacheMiss=0
10-19 14:50:14.236 D/CellLocator(  976): Found cell location: Position [redacted]
10-19 14:50:14.236 D/androidNlpServiceThread(  976): reporting Location[mProvider=network,mTime=1350672614246,mLatitude=40.8390777,mLongitude=-73.6949326,mHasAltitude=false,mAltitude=0.0,mHasSpeed=false,mSpeed=0.0,mHasBearing=false,mBearing=0.0,mHasAccuracy=true,mAccuracy=1123.0,mExtras=Bundle[{networkLocationSource=cached, networkLocationType=cell}]]
10-19 14:50:14.243 D/ClientReporter(  976): reported location
10-19 14:50:14.595 W/GpsLocationProvider(  496): Unneeded remove listener for uid 1000
10-19 14:50:14.595 D/libgps_GpsMgr(  496): schedGps() mode: 3, tbf: 0, accuracy: 0, perf: 0, pAgps: null
10-19 14:50:14.595 D/libgps  (  496): GpsInterface_stop()
10-19 14:50:14.603 D/libgps  (  496): action_thread_main(): BP not in session, sending fake END callback
10-19 14:50:14.603 D/libgps  (  496): status_cb: GPS_STATUS_SESSION_END (2)
10-19 14:50:14.603 D/libgps_GpsMgr(  496): sched() set mode: 3, tbf: 0
10-19 14:50:14.634 D/libgps  (  496): GpsInterface_inject_location( 40.839078, -73.694933, 1123.000 )
10-19 14:50:14.634 D/libgps  (  496): MPDINJPOS_REQ msg id 12015

If your app process doesn't have any activities in the foreground or foregrounded services it can be killed at any time by the system to free memory for other apps. 如果您的应用程序进程在前台或前台服务中没有任何活动,系统可以随时终止它以释放其他应用程序的内存。

So in your case, after Activity.onPause has been called when the users leaves your app using for example the home button your app process can be killed at any time. 因此,在您的情况下,当用户使用例如主页按钮离开您的应用程序时调用Activity.onPause后,您的应用程序进程可以随时终止。

http://developer.android.com/guide/components/processes-and-threads.html#Lifecycle http://developer.android.com/guide/components/processes-and-threads.html#Lifecycle

You need to make some sort service so that it will continue to run even if your app is not running. 您需要进行一些排序服务,以便即使您的应用程序未运行它也会继续运行。 (your app can be killed anytime if it's not in the foreground and the system needs memory). (如果您的应用程序不在前台并且系统需要内存,则可以随时将其杀死)。

To do this, you need to write native code (Java for Android app). 为此,您需要编写本机代码(适用于Android应用程序的Java)。 Look in the official doc on how to write a service or better a phonegap plugin. 在官方文档中查看如何编写服务或更好的phonegap插件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在应用程序中的背景中带有插件的位置phonegap cordova for android - Location in Background With Plugin in App phonegap cordova for android 使用PhoneGap在后台进行位置跟踪 - Location tracking in background with PhoneGap 在后台收集位置信息的最佳解决方案是什么? - What is the best solution for collecting location info in the background? 在后台运行应用程序时获取GPS位置更新 - Getting GPS location updates while app in the background Phonegap App在后台运行? - Phonegap App running in background? 当应用程序在后台时停止在 ViewModel 中收集流 - Stop collecting Flow in ViewModel when app in background 基于PhoneGap位置的应用程序和可移植性 - PhoneGap Location Based App and Portibility 在Google文档中收集报告时应用崩溃 - App crashing while collecting reports in google doc 当应用程序在后台尝试访问位置时,是否可以获取日志? - Is it possible to get logs for when an app is trying to access location while in the background? 当应用程序在Cordova Android应用程序中处于后台时获取用户位置 - Get user location while app is background in cordova android application
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM