Reputation: 3550
I'm developing application where I have Activity that records GPS positions. It registers for LocationListener updates and stores recorded Location to SQLite database. My problem is that when the user hides my app or runs another app, my app and recording activity goes to background and may be killed by system. Thus, no GPS data is stored. I want that my app and recording activity still records GPS locations even if the app goes to background. How to achieve that?
Thanks
Upvotes: 0
Views: 843
Reputation: 29670
Use other components of Android like BroadcastReceiver
or Service
which can run in background without any GUI.
public class UploadData extends BroadcastReceiver
{
private static LocationManager locationManager = null;
private static LocationListener locationListener = null;
@Override
public void onReceive(Context context, Intent intent)
{
// Create and AlarmManager that will periodically fetch the GPS
}
}
In case of Service,
public class myservice extends Service
{
LocationManager locationManager = null;
LocationListener loclistener = null;
// Bind it, Its important
public IBinder onBind(Intent intent)
{
return null;
}
@Override
public void onCreate()
{
// Use AlarmManager to fetch the GPS periodically.
}
}
Upvotes: 0