Note that there are some explanatory texts on larger screens.

plurals
  1. POUse service to get GPS location, android?
    primarykey
    data
    text
    <p>This is first time I am using service and it sure looks a lot complicated from activity.</p> <p>So I am trying to get the user's location after he has closed my application with the service.</p> <p>This is my service class.</p> <pre><code>public class LocTrack extends Service { GPSTracker gp; @Override public void onCreate() { gp = new GPSTracker(getApplicationContext()); onLocationChanged(gp); super.onCreate(); } @Override public void onDestroy() { // TODO Auto-generated method stub super.onDestroy(); } @Override public int onStartCommand(Intent intent, int flags, int startId) { // TODO Auto-generated method stub return Service.START_STICKY; } @Override public IBinder onBind(Intent arg0) { // TODO Auto-generated method stub return null; } public void onLocationChanged(GPSTracker track) { // Getting latitude double latitude = track.getLatitude(); // Getting longitude double longitude = track.getLongitude(); Geocoder geocoder = new Geocoder(LocTrack.this, Locale.getDefault()); try { List&lt;Address&gt; addresses = geocoder.getFromLocation(latitude, longitude,1); Log.e("Addresses","--&gt;"+addresses); } catch (IOException e) { e.printStackTrace(); } } } </code></pre> <p>Please tell me what am I doing my wrong. If I use the code in an activity class then I am able to get the address in the logcat but not when i use service.</p> <p>This is how i am calling the service from activity</p> <pre><code> Intent intent = new Intent(MainActivity.this, LocTrack.class); startService(intent); </code></pre>
    singulars
    1. This table or related slice is empty.
    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