Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I think that a "GPS collector" is more suited to a Service.</p> <p>Your service could look like:</p> <pre><code>import android.app.Service; import android.content.Context; import android.content.Intent; import android.location.Location; import android.location.LocationListener; import android.location.LocationManager; import android.os.Binder; import android.os.Bundle; import android.os.IBinder; public class GPSCollectService extends Service implements LocationListener{ private LocationManager mLocationManager; public class GPSBinder extends Binder { GPSCollectService getService() { return GPSCollectService.this; } } @Override public IBinder onBind(Intent intent) { return mBinder; } private final IBinder mBinder = new GPSBinder(); @Override public int onStartCommand(Intent intent, int flags, int startId) { return START_STICKY; } @Override public void onCreate() { startservice(); } @Override public void onDestroy(){ mLocationManager.removeUpdates(this); mLocationManager = null; } private void startservice() { mLocationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE); mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 0, this); } public void onLocationChanged(Location arg0) { if (arg0 != null){ //Your database storing code here } } public void onProviderDisabled(String arg0) {} public void onProviderEnabled(String arg0) {} public void onStatusChanged(String arg0, int arg1, Bundle arg2) {} } </code></pre> <p>and in your main activity:</p> <pre><code>private Intent msvcGPSCollect = null; @Override public void onDestroy(){ finishServices(); super.onDestroy(); } private void startBackgroundServices(){ msvcGPSCollect = new Intent(this, GPSCollectService.class); startService(msvcGPSCollect); } private void finishServices(){ if (msvcGPSCollect != null) stopService(msvcGPSCollect); } </code></pre> <hr> <p>EDIT: I've not actually answered your question!</p> <p>Where I've put:</p> <pre><code>\\ Your database storing code here </code></pre> <p>you'll need to call your own Async Task. </p> <p>Example of an async task call:</p> <pre><code>PushGPSAsync myAsyncTask = new PushGPSAsync(); myAsyncTask.execute(); </code></pre> <p>Example of an async task:</p> <pre><code>public class PushGPSAsync extends AsyncTask&lt;Void, Void, Boolean&gt;{ @Override protected Boolean doInBackground(Void... params){ pushGPS(); return null; } @Override public void onPostExecute(Boolean result){ //Call a post execute function here } } private boolean pushGPS(Void... params){ //store the GPS } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload