Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. 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.

The Android version seems to be prone to crashing while it is in the background. 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. It seems a WIN DEATH occurs on the CCWalkerActivity shortly after Activity Manager calls "No longer want" on the process (both are bolded below). However, I can't determine why this is happening and why it is happening so frequently.

Is this a problem with Phonegap? Would creating a plugin that could the process a foreground service (using startForeground()) be beneficial?

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
like image 269
Adam Zeldis Avatar asked Oct 19 '12 20:10

Adam Zeldis


2 Answers

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.

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

like image 178
Johan Appelgren Avatar answered Oct 27 '22 17:10

Johan Appelgren


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). Look in the official doc on how to write a service or better a phonegap plugin.

like image 43
wmfairuz Avatar answered Oct 27 '22 17:10

wmfairuz