2012-10-19 4 views
9

Ich habe eine App in PhoneGap, die navigator.geolocation Aufrufe verwendet, um die Koordinaten des mobilen Geräts zu verfolgen. Der Benutzer hat die Kontrolle, das Tracking zu starten und es zu beenden. Die App wurde so erstellt, dass sie im Hintergrund Koordinatendaten erhält. Die App ist für Android- und iOS-Geräte freigegeben.Phonegap App stirbt im Hintergrund beim Sammeln von Standort

Die Android-Version scheint während des Hintergrunds anfällig für Abstürze zu sein. Bei einigen Handys ist es in Ordnung, aber bei vielen von ihnen wird die App einfach absterben, während sie im Hintergrund Koordinatendaten sammeln soll. Ich habe unten ein LogCat-Log geschrieben. Es scheint, ein WIN DEATH tritt auf dem kurz nach Activity Manager ruft "nicht mehr wollen" auf den Prozess (beide sind fett unten). Ich kann jedoch nicht feststellen, warum dies geschieht und warum es so häufig passiert.

Ist das ein Problem mit Phonegap? Wäre es hilfreich, ein Plugin zu erstellen, mit dem ein Vordergrund-Service (unter Verwendung von startForeground()) verarbeitet werden kann?

 
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.[email protected]40552710 with period 45 
10-19 14:50:14.118 D/androidNetworkLocationListeners( 976): Still have listener com.[email protected]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.[email protected]40552710 with period 86400 
10-19 14:50:14.228 D/androidNetworkLocationListeners( 976): Still have listener com.[email protected]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 

Antwort

2

Wenn Ihr App-Prozess hat keine Aktivitäten im Vordergrund oder im Vordergrund Dienst kann durch das System jederzeit getötet werden, um Speicher für andere Anwendungen freizugeben.

In Ihrem Fall, nachdem Activity.onPause aufgerufen wurde, wenn die Nutzer Ihre App verlassen, zum Beispiel mit der Home-Taste, kann Ihr App-Prozess jederzeit beendet werden.

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

1

Sie brauchen eine Art Service zu machen, damit sie laufen weiter, auch wenn die App nicht läuft. (Ihre App kann jederzeit beendet werden, wenn sie nicht im Vordergrund ist und das System Speicher benötigt).

Um dies zu tun, müssen Sie nativen Code (Java für Android App) schreiben. Sehen Sie im offiziellen Dokument nach, wie Sie einen Dienst oder ein Phonegap-Plugin schreiben können.