Issue
i just implemented an application that use Location Updates with the new Google 2013 I/O Api (Google Play Services) : http://developer.android.com/training/location/receive-location-updates.html
My application works (in background as well) but the problem is, if my device is out of memory, or i just clean manually the memory, the service just stops working. No Location Updates anymore the OS kills the service and it's not restarting it if memory is available.
In Android Service Documentation i found:
The Android system will force-stop a service only when memory is low and it must recover system resources for the activity that has user focus. If the service is bound to an activity that has user focus, then it's less likely to be killed, and if the service is declared to run in the foreground (discussed later), then it will almost never be killed.
How can i force a Google Play Service to a foreground service? (Like Messanger etc)
Thanks!
Solution
I was facing the same problem and I had to bring the Service to Foreground and Alhamdullilah the following worked for me.
Add the following in your onStartCommand() method if your service is not bound.
.......
Notification.Builder builder = new Builder(this);
builder.setSmallIcon(R.drawable.ic_launcher);
builder.setContentTitle("content title");
builder.setTicker("ticker");
builder.setContentText("content text").setWhen(System.currentTimeMillis());
Notification notification = builder.build();
notification.flags |= Notification.FLAG_NO_CLEAR;
startForeground(42, notification);
return START_STICKY;
Answered By - Lazy Ninja
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.