Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid Repeating Alarm invoking a service
    primarykey
    data
    text
    <p>I am trying to send GPS coordinates to server in every 1 minute interval through a background service . It invokes the service for thee first time but it doesn't repeat it .</p> <p>Code for setting the alarm:</p> <pre><code>Intent gpsIntent = new Intent(CheckInActivity.this, GoogleMapService.class); gpsPendingIntent = PendingIntent.getService(CheckInActivity.this, 0, gpsIntent, 0); AlarmManager alarmManager_gps = (AlarmManager)getSystemService(ALARM_SERVICE); Calendar calendar_gps = Calendar.getInstance(); calendar_gps.add(Calendar.SECOND, 20); alarmManager_gps.setRepeating(AlarmManager.RTC_WAKEUP, calendar_gps.getTimeInMillis(), TimeUnit.MINUTES.toMillis(1), gpsPendingIntent); </code></pre> <p>Service</p> <pre><code> public class GoogleMapService extends Service { private boolean gps_enabled = false; private boolean network_enabled = false; private static Location sLocation; private LocationManager locManager; private LocationListener locListener = new MyLocationListener(); private CallBack callback; @Override public void onCreate() { } @Override public IBinder onBind(Intent intent) { Log.w(null,"GPS Service called"); locManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); try { gps_enabled = locManager.isProviderEnabled(LocationManager.GPS_PROVIDER); } catch (Exception ex) { } try { network_enabled = locManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER); } catch (Exception ex) { } if (gps_enabled) { locManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locListener); } if (network_enabled) { locManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locListener); } callback = new CallBack() { public void onResult(Boolean result) { // TODO Auto-generated method stub } public void onProgress() { // TODO Auto-generated method stub } }; return null; } @Override public void onDestroy() { super.onDestroy(); } @Override public void onStart(Intent intent, int startId) { super.onStart(intent, startId); } @Override public boolean onUnbind(Intent intent) { return super.onUnbind(intent); } class MyLocationListener implements LocationListener { public void onLocationChanged(Location location) { if (location != null) { // This needs to stop getting the location data and save the battery power. locManager.removeUpdates(locListener); sLocation = location; Model.coordinates = location.getLatitude() + "," + location.getLongitude(); try{ SendGPSCoordinatesOperation task = new SendGPSCoordinatesOperation(callback); task.execute(""); Log.w(null,"Sent"); } catch(Exception e){ Log.w(null,"Couldn't be sent"); } Log.w(null,"The coordinates are"+Model.coordinates); } } public void onProviderDisabled(String provider) { // TODO Auto-generated method stub } public void onProviderEnabled(String provider) { // TODO Auto-generated method stub } public void onStatusChanged(String provider, int status, Bundle extras) { // TODO Auto-generated method stub } } } </code></pre> <p>EDIT : AndroidManifest code </p> <p></p>
    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.
 

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