You can do couple of things.
1) detach any UI life-cycle components, preferably switch your service to a :remote process, using the manifest. This way if your activity crashes/gets killed, your service will remain unaffected because they were on different processes. Look into android IPC (simple way to communicate between your activity and this service when on different process is to use sockets on local host)
<service
android:name="myName.GPS"
android:enabled="true"
android:exported="false"
android:process=":remote">
</service>
2) make it a high priority foreground service (this will create a persistent notification)
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
//retrieve persisted data here
final Intent i = new Intent(this, ClassNameOfService.class);
i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
final PendingIntent pi = PendingIntent.getActivity(this, 0, i, 0);
final NotificationCompat.Builder note =
new NotificationCompat.Builder(this)
.setLargeIcon(BitmapFactory.decodeResource(getResources(),R.drawable.icon))
.setSmallIcon(R.drawable.icon)
.setContentTitle("GPS Running")
.setOngoing(true)
.setContentIntent(pi);
startForeground(10001, note.build()); //replace 10001 with whatever id you like
return super.onStartCommand(intent, flags, startId);
}
3) handle onLowMemory, onDestroy etc., gracefully so that you can restart your service. You can use shared prefs, or create an sql database to persist your data, depending on what suits your needs. Your service will get killed at one point or the other. So its better to have a persistence strategy.
@Override
public void onDestroy() {
//persist your data here
super.onDestroy();
}