Re: [android-developers] Re: GPS Background Service Stops Receiving Updates
Hi, re - I am holding the home button and the list of apps comes up and I swipe away my app to kill it. This is what others have mentioned above. I don't know if this is samsung only or not. Maybe this method is supposed to kill all running services and processes of the app and is not a good way to test. Ok I think you are referring to the rectangular 'Recent Apps' button, not the Home button, but I get what you mean about swiping to close a recent Activity from that list. And yes, what Treking said about StartForeground. Regards On Tuesday, November 25, 2014 7:29:07 AM UTC+11, Tony Pitman wrote: It looks like calling startForeground was the key. I am still not able to kill the app using the method mentioned above, but at least now when I let the app sit for a long period of time the GPS notifications keep coming into the service even when it looks like the app has been shut down by the OS for lack of use. I do have another related question. When I did my service I was following the example of a service on the google dev site. This is the link to what I followed: http://developer.android.com/guide/components/services.html You will notice about the middle of the page there is the example code that I followed and then modified. They use a HandlerThread to create the Looper that gets used in the mServiceHandler thread to process the actual work. They pass in a parameter to that HandlerThread called Process.THREAD_PRIORITY_BACKGROUND. Is this different than using the startForeground that now fixed my issue? I left that HandlerThread the way it was and it now works with the startForeground. Thanks! On Monday, November 24, 2014 8:17:18 AM UTC-7, Tony Pitman wrote: Thank you everyone for the replies. Here are my responses: I am holding the home button and the list of apps comes up and I swipe away my app to kill it. This is what others have mentioned above. I don't know if this is samsung only or not. Maybe this method is supposed to kill all running services and processes of the app and is not a good way to test. I tried giving the service a different process. I tried 2 things. First I just added the android:process tag to my service. I gave it a name with the ':' in front so it would be private to my app. This did not change anything. The service still dies when I kill the app. The other thing I noticed is when I go to the Settings - Application Manager - Running I see my app. If I tap on it to see what it is doing I get the following sections / information: Active App: MyApp 1 process and 1 service Services: MyService Start by application Processes: MyApp com.mycompany.myappspace:MyService Main process in use. So I decided to try adding the android:process section to the main application entry in the xml as well. I gave it a different name just in case. I called it MyApp instead of MyService. This did not make any difference. The information shown in the settings panel were the same. So am I to assume that the service is running in the same process as the app so that when I kill the app using the method above that is why the service is also dying? Is killing the app that way the wrong way to test? The whole reason I am doing this is because originally I just put my gps stuff inside the app itself. I would start my app and then many hours later I would enter the geofence area I had set up and the app did not trigger what I wanted it to do. I would go to the app and it looked like it was starting all over. Maybe I should just start my app and let it run for several hours and see if the service keeps going. Thanks for all the help. On Monday, November 24, 2014 7:58:36 AM UTC-7, Mukesh Srivastav wrote: As my understanding here, the service was stopped some where in the code and hence it is behaving like that. On Mon, Nov 24, 2014 at 7:38 PM, Mark Phillips ma...@phillipsmarketing.biz wrote: On my Samsung Galaxy 4 phone from T-Mobile, I can hold down the home button and get a list of running apps. I can kill each one individually with a swipe, and there is a trashcan icon at the bottom of the screen that will kill all the apps running. I use this feature to extend my battery time when the batter is getting low. It may be a special Samsung app that does this. Mark On Mon, Nov 24, 2014 at 1:13 AM, gjs garyjam...@gmail.com wrote: Hi, What do you mean by - ...I test this by holding down the home button and killing my app ? If I start an app, then press hold down the Home button, the app that was running is sent to the background (not killed) the only option that appears is a circle that pops up to run Google Now - if I then swipe upwards. There is no option to kill any apps via the Home button interaction you described as far as I know, I tested this on (stock) Nexus 5 with Android 5 as well as Sony Xperia 2 with Android 4.4 phone devices. The only
Re: [android-developers] Re: GPS Background Service Stops Receiving Updates
Party is not over you might find the issue like 1. Though the GPS and Network is disable, The Location manger returns Network provider and returns the invalid/long distance lat and long data. 2.Sometimes, though you put your tablet/application in one place, the Network/GPS Provider will return the lat longs of the different location. 3.Though you mention the distance and time, the Network provider return the data of Asia pacific. 4.At a times, you might also get the locationmanager object as null, though it work the full day but it fails at one point. 5.and also, what is the logic you have put to avoid the duplicate lat and long to be uploaded. I had the situation earlier and i have shared you my experience. On Tue, Nov 25, 2014 at 1:58 PM, gjs garyjamessi...@gmail.com wrote: Hi, re - I am holding the home button and the list of apps comes up and I swipe away my app to kill it. This is what others have mentioned above. I don't know if this is samsung only or not. Maybe this method is supposed to kill all running services and processes of the app and is not a good way to test. Ok I think you are referring to the rectangular 'Recent Apps' button, not the Home button, but I get what you mean about swiping to close a recent Activity from that list. And yes, what Treking said about StartForeground. Regards On Tuesday, November 25, 2014 7:29:07 AM UTC+11, Tony Pitman wrote: It looks like calling startForeground was the key. I am still not able to kill the app using the method mentioned above, but at least now when I let the app sit for a long period of time the GPS notifications keep coming into the service even when it looks like the app has been shut down by the OS for lack of use. I do have another related question. When I did my service I was following the example of a service on the google dev site. This is the link to what I followed: http://developer.android.com/guide/components/services.html You will notice about the middle of the page there is the example code that I followed and then modified. They use a HandlerThread to create the Looper that gets used in the mServiceHandler thread to process the actual work. They pass in a parameter to that HandlerThread called Process.THREAD_PRIORITY_BACKGROUND. Is this different than using the startForeground that now fixed my issue? I left that HandlerThread the way it was and it now works with the startForeground. Thanks! On Monday, November 24, 2014 8:17:18 AM UTC-7, Tony Pitman wrote: Thank you everyone for the replies. Here are my responses: I am holding the home button and the list of apps comes up and I swipe away my app to kill it. This is what others have mentioned above. I don't know if this is samsung only or not. Maybe this method is supposed to kill all running services and processes of the app and is not a good way to test. I tried giving the service a different process. I tried 2 things. First I just added the android:process tag to my service. I gave it a name with the ':' in front so it would be private to my app. This did not change anything. The service still dies when I kill the app. The other thing I noticed is when I go to the Settings - Application Manager - Running I see my app. If I tap on it to see what it is doing I get the following sections / information: Active App: MyApp 1 process and 1 service Services: MyService Start by application Processes: MyApp com.mycompany.myappspace:MyService Main process in use. So I decided to try adding the android:process section to the main application entry in the xml as well. I gave it a different name just in case. I called it MyApp instead of MyService. This did not make any difference. The information shown in the settings panel were the same. So am I to assume that the service is running in the same process as the app so that when I kill the app using the method above that is why the service is also dying? Is killing the app that way the wrong way to test? The whole reason I am doing this is because originally I just put my gps stuff inside the app itself. I would start my app and then many hours later I would enter the geofence area I had set up and the app did not trigger what I wanted it to do. I would go to the app and it looked like it was starting all over. Maybe I should just start my app and let it run for several hours and see if the service keeps going. Thanks for all the help. On Monday, November 24, 2014 7:58:36 AM UTC-7, Mukesh Srivastav wrote: As my understanding here, the service was stopped some where in the code and hence it is behaving like that. On Mon, Nov 24, 2014 at 7:38 PM, Mark Phillips ma...@phillipsmarketing.biz wrote: On my Samsung Galaxy 4 phone from T-Mobile, I can hold down the home button and get a list of running apps. I can kill each one individually with a swipe, and there is a trashcan icon at the bottom of the screen that will kill
Re: [android-developers] Re: GPS Background Service Stops Receiving Updates
Hi, For - 1. Check if GPS is supported if LocationManger is disabled, if so prompt the user to re-enable it, be kind take them directly to the applicable Android-Setting screen to do this. (See 4 also). 2. Where possible I ignore LocationManager use the raw GPS NMEA data, http://developer.android.com/reference/android/location/LocationManager.html#addNmeaListener(android.location.GpsStatus.NmeaListener) but be aware some older devices don't support this such as Motorola Defy+ 3. Date Time from GPS is UTC unless you localise it, (but see 2.) 4. I guess this may happen, perhaps that is related to 1, or the device does not have onboard GPS receiver (eg HP Slate 7 tablet) - then offer to connect to an external Bluetooth GPS receiver use that instead. 5. That is never an issue if you 'key' the lat lon data with GPS date/time stamps, if duplicate lat lon is an issue in some upload then your server app logic is probably incorrect. Regards On Tuesday, November 25, 2014 9:30:52 PM UTC+11, Mukesh Srivastav wrote: Party is not over you might find the issue like 1. Though the GPS and Network is disable, The Location manger returns Network provider and returns the invalid/long distance lat and long data. 2.Sometimes, though you put your tablet/application in one place, the Network/GPS Provider will return the lat longs of the different location. 3.Though you mention the distance and time, the Network provider return the data of Asia pacific. 4.At a times, you might also get the locationmanager object as null, though it work the full day but it fails at one point. 5.and also, what is the logic you have put to avoid the duplicate lat and long to be uploaded. I had the situation earlier and i have shared you my experience. On Tue, Nov 25, 2014 at 1:58 PM, gjs garyjam...@gmail.com javascript: wrote: Hi, re - I am holding the home button and the list of apps comes up and I swipe away my app to kill it. This is what others have mentioned above. I don't know if this is samsung only or not. Maybe this method is supposed to kill all running services and processes of the app and is not a good way to test. Ok I think you are referring to the rectangular 'Recent Apps' button, not the Home button, but I get what you mean about swiping to close a recent Activity from that list. And yes, what Treking said about StartForeground. Regards On Tuesday, November 25, 2014 7:29:07 AM UTC+11, Tony Pitman wrote: It looks like calling startForeground was the key. I am still not able to kill the app using the method mentioned above, but at least now when I let the app sit for a long period of time the GPS notifications keep coming into the service even when it looks like the app has been shut down by the OS for lack of use. I do have another related question. When I did my service I was following the example of a service on the google dev site. This is the link to what I followed: http://developer.android.com/guide/components/services.html You will notice about the middle of the page there is the example code that I followed and then modified. They use a HandlerThread to create the Looper that gets used in the mServiceHandler thread to process the actual work. They pass in a parameter to that HandlerThread called Process.THREAD_PRIORITY_BACKGROUND. Is this different than using the startForeground that now fixed my issue? I left that HandlerThread the way it was and it now works with the startForeground. Thanks! On Monday, November 24, 2014 8:17:18 AM UTC-7, Tony Pitman wrote: Thank you everyone for the replies. Here are my responses: I am holding the home button and the list of apps comes up and I swipe away my app to kill it. This is what others have mentioned above. I don't know if this is samsung only or not. Maybe this method is supposed to kill all running services and processes of the app and is not a good way to test. I tried giving the service a different process. I tried 2 things. First I just added the android:process tag to my service. I gave it a name with the ':' in front so it would be private to my app. This did not change anything. The service still dies when I kill the app. The other thing I noticed is when I go to the Settings - Application Manager - Running I see my app. If I tap on it to see what it is doing I get the following sections / information: Active App: MyApp 1 process and 1 service Services: MyService Start by application Processes: MyApp com.mycompany.myappspace:MyService Main process in use. So I decided to try adding the android:process section to the main application entry in the xml as well. I gave it a different name just in case. I called it MyApp instead of MyService. This did not make any difference. The information shown in the settings panel were the same. So am I to assume that the service is running in the same process as
[android-developers] Re: GPS Background Service Stops Receiving Updates
Try running it in a different process: android:processThe name of the process where the service is to run. Normally, all components of an application run in the default process created for the application. It has the same name as the application package. The application http://developer.android.com/guide/topics/manifest/application-element.html element's process http://developer.android.com/guide/topics/manifest/application-element.html#proc attribute can set a different default for all components. But component can override the default with its own process attribute, allowing you to spread your application across multiple processes. If the name assigned to this attribute begins with a colon (':'), a new process, private to the application, is created when it's needed and the service runs in that process. If the process name begins with a lowercase character, the service will run in a global process of that name, provided that it has permission to do so. This allows components in different applications to share a process, reducing resource usage. Nir On Sunday, November 23, 2014 8:44:45 AM UTC+2, Tony Pitman wrote: I am writing an app that needs to get gps location information in the background. I created a class derived from Service to do this. I copied the example on the Android developer site about making a background service. It uses the ServiceHandler thread to do the work. I use location manager and set up the receiving of updates. I have my main activity create the service using the normal way like this: Intent intent = new Intent(_context, MyService.class); _context.startService(intent); Inside my service I create the location manager and start getting location updates. This works great so far. I am doing this as a service because I want my service to receive updates even if my application is shut down. I test this by holding down the home button and killing my app. The problem is that as soon as I kill my app the service stops getting updates. The service does not go away, as far as I can tell, it just quits receiving GPS updates. As long as I leave the app running, even in the background, the service keeps getting the GPS updates. Can someone tell me how to continue to get GPS updates in my service even if the app that started it gets killed? I have some settings in my AndroidManifest.xml that might be affecting it. I have the service set up so it is not exported and has permissions. I do this because I don't want other applications to use my service. Could these be affecting it? Here is my service entry in the xml: service android:name=com.mycompany.mypackage.MyService android:permission=com.mycompany.MY_SERVICE android:exported=false / Just after that outside of the application tag I have this: permission android:name=com.mycompany. MY_SERVICE/ uses-permission android:name=com.mycompany. MY_SERVICE / -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en --- You received this message because you are subscribed to the Google Groups Android Developers group. To unsubscribe from this group and stop receiving emails from it, send an email to android-developers+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[android-developers] Re: GPS Background Service Stops Receiving Updates
Hi, What do you mean by - ...I test this by holding down the home button and killing my app ? If I start an app, then press hold down the Home button, the app that was running is sent to the background (not killed) the only option that appears is a circle that pops up to run Google Now - if I then swipe upwards. There is no option to kill any apps via the Home button interaction you described as far as I know, I tested this on (stock) Nexus 5 with Android 5 as well as Sony Xperia 2 with Android 4.4 phone devices. The only (stock) standard way I know to kill apps is via Android Settings-Apps-Downloaded-(select App)-Press 'Force stop' button. I'd suggest you try in the service manifest entry android:exported=true if that is ok for your app. Other things to try are android:process also make sure you are using startForeground(..) stopForeground(.) calls in your service or it will be killed by the OS after a period of time and finally you probably need to use a wake lock to keep the CPU running when the display is turned off. I use these settings to get a GPS (background) Service to continue to run ok indefinitely after the uses exits my app or presses the home button or turns the screen off. (But be warned that these actions can deplete the device battery fairly quickly which many users do not like). The user can still always kill the app background service even when the app is stopped / service in the background via Android Settings-Apps-Downloaded-(select App)-Press 'Force stop', there is nothing your app can do to avoid this... Regards On Sunday, November 23, 2014 5:44:45 PM UTC+11, Tony Pitman wrote: I am writing an app that needs to get gps location information in the background. I created a class derived from Service to do this. I copied the example on the Android developer site about making a background service. It uses the ServiceHandler thread to do the work. I use location manager and set up the receiving of updates. I have my main activity create the service using the normal way like this: Intent intent = new Intent(_context, MyService.class); _context.startService(intent); Inside my service I create the location manager and start getting location updates. This works great so far. I am doing this as a service because I want my service to receive updates even if my application is shut down. I test this by holding down the home button and killing my app. The problem is that as soon as I kill my app the service stops getting updates. The service does not go away, as far as I can tell, it just quits receiving GPS updates. As long as I leave the app running, even in the background, the service keeps getting the GPS updates. Can someone tell me how to continue to get GPS updates in my service even if the app that started it gets killed? I have some settings in my AndroidManifest.xml that might be affecting it. I have the service set up so it is not exported and has permissions. I do this because I don't want other applications to use my service. Could these be affecting it? Here is my service entry in the xml: service android:name=com.mycompany.mypackage.MyService android:permission=com.mycompany.MY_SERVICE android:exported=false / Just after that outside of the application tag I have this: permission android:name=com.mycompany. MY_SERVICE/ uses-permission android:name=com.mycompany. MY_SERVICE / -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en --- You received this message because you are subscribed to the Google Groups Android Developers group. To unsubscribe from this group and stop receiving emails from it, send an email to android-developers+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [android-developers] Re: GPS Background Service Stops Receiving Updates
On my Samsung Galaxy 4 phone from T-Mobile, I can hold down the home button and get a list of running apps. I can kill each one individually with a swipe, and there is a trashcan icon at the bottom of the screen that will kill all the apps running. I use this feature to extend my battery time when the batter is getting low. It may be a special Samsung app that does this. Mark On Mon, Nov 24, 2014 at 1:13 AM, gjs garyjamessi...@gmail.com wrote: Hi, What do you mean by - ...I test this by holding down the home button and killing my app ? If I start an app, then press hold down the Home button, the app that was running is sent to the background (not killed) the only option that appears is a circle that pops up to run Google Now - if I then swipe upwards. There is no option to kill any apps via the Home button interaction you described as far as I know, I tested this on (stock) Nexus 5 with Android 5 as well as Sony Xperia 2 with Android 4.4 phone devices. The only (stock) standard way I know to kill apps is via Android Settings-Apps-Downloaded-(select App)-Press 'Force stop' button. I'd suggest you try in the service manifest entry android:exported=true if that is ok for your app. Other things to try are android:process also make sure you are using startForeground(..) stopForeground(.) calls in your service or it will be killed by the OS after a period of time and finally you probably need to use a wake lock to keep the CPU running when the display is turned off. I use these settings to get a GPS (background) Service to continue to run ok indefinitely after the uses exits my app or presses the home button or turns the screen off. (But be warned that these actions can deplete the device battery fairly quickly which many users do not like). The user can still always kill the app background service even when the app is stopped / service in the background via Android Settings-Apps-Downloaded-(select App)-Press 'Force stop', there is nothing your app can do to avoid this... Regards On Sunday, November 23, 2014 5:44:45 PM UTC+11, Tony Pitman wrote: I am writing an app that needs to get gps location information in the background. I created a class derived from Service to do this. I copied the example on the Android developer site about making a background service. It uses the ServiceHandler thread to do the work. I use location manager and set up the receiving of updates. I have my main activity create the service using the normal way like this: Intent intent = new Intent(_context, MyService.class); _context.startService(intent); Inside my service I create the location manager and start getting location updates. This works great so far. I am doing this as a service because I want my service to receive updates even if my application is shut down. I test this by holding down the home button and killing my app. The problem is that as soon as I kill my app the service stops getting updates. The service does not go away, as far as I can tell, it just quits receiving GPS updates. As long as I leave the app running, even in the background, the service keeps getting the GPS updates. Can someone tell me how to continue to get GPS updates in my service even if the app that started it gets killed? I have some settings in my AndroidManifest.xml that might be affecting it. I have the service set up so it is not exported and has permissions. I do this because I don't want other applications to use my service. Could these be affecting it? Here is my service entry in the xml: service android:name=com.mycompany.mypackage.MyService android:permission=com.mycompany.MY_SERVICE android:exported=false / Just after that outside of the application tag I have this: permission android:name=com.mycompany. MY_SERVICE/ uses-permission android:name=com.mycompany. MY_SERVICE / -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en --- You received this message because you are subscribed to the Google Groups Android Developers group. To unsubscribe from this group and stop receiving emails from it, send an email to android-developers+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en --- You received this message because you are
Re: [android-developers] Re: GPS Background Service Stops Receiving Updates
As my understanding here, the service was stopped some where in the code and hence it is behaving like that. On Mon, Nov 24, 2014 at 7:38 PM, Mark Phillips m...@phillipsmarketing.biz wrote: On my Samsung Galaxy 4 phone from T-Mobile, I can hold down the home button and get a list of running apps. I can kill each one individually with a swipe, and there is a trashcan icon at the bottom of the screen that will kill all the apps running. I use this feature to extend my battery time when the batter is getting low. It may be a special Samsung app that does this. Mark On Mon, Nov 24, 2014 at 1:13 AM, gjs garyjamessi...@gmail.com wrote: Hi, What do you mean by - ...I test this by holding down the home button and killing my app ? If I start an app, then press hold down the Home button, the app that was running is sent to the background (not killed) the only option that appears is a circle that pops up to run Google Now - if I then swipe upwards. There is no option to kill any apps via the Home button interaction you described as far as I know, I tested this on (stock) Nexus 5 with Android 5 as well as Sony Xperia 2 with Android 4.4 phone devices. The only (stock) standard way I know to kill apps is via Android Settings-Apps-Downloaded-(select App)-Press 'Force stop' button. I'd suggest you try in the service manifest entry android:exported=true if that is ok for your app. Other things to try are android:process also make sure you are using startForeground(..) stopForeground(.) calls in your service or it will be killed by the OS after a period of time and finally you probably need to use a wake lock to keep the CPU running when the display is turned off. I use these settings to get a GPS (background) Service to continue to run ok indefinitely after the uses exits my app or presses the home button or turns the screen off. (But be warned that these actions can deplete the device battery fairly quickly which many users do not like). The user can still always kill the app background service even when the app is stopped / service in the background via Android Settings-Apps-Downloaded-(select App)-Press 'Force stop', there is nothing your app can do to avoid this... Regards On Sunday, November 23, 2014 5:44:45 PM UTC+11, Tony Pitman wrote: I am writing an app that needs to get gps location information in the background. I created a class derived from Service to do this. I copied the example on the Android developer site about making a background service. It uses the ServiceHandler thread to do the work. I use location manager and set up the receiving of updates. I have my main activity create the service using the normal way like this: Intent intent = new Intent(_context, MyService.class); _context.startService(intent); Inside my service I create the location manager and start getting location updates. This works great so far. I am doing this as a service because I want my service to receive updates even if my application is shut down. I test this by holding down the home button and killing my app. The problem is that as soon as I kill my app the service stops getting updates. The service does not go away, as far as I can tell, it just quits receiving GPS updates. As long as I leave the app running, even in the background, the service keeps getting the GPS updates. Can someone tell me how to continue to get GPS updates in my service even if the app that started it gets killed? I have some settings in my AndroidManifest.xml that might be affecting it. I have the service set up so it is not exported and has permissions. I do this because I don't want other applications to use my service. Could these be affecting it? Here is my service entry in the xml: service android:name=com.mycompany.mypackage.MyService android:permission=com.mycompany.MY_SERVICE android:exported=false / Just after that outside of the application tag I have this: permission android:name=com.mycompany. MY_SERVICE/ uses-permission android:name=com.mycompany. MY_SERVICE / -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en --- You received this message because you are subscribed to the Google Groups Android Developers group. To unsubscribe from this group and stop receiving emails from it, send an email to android-developers+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this
Re: [android-developers] Re: GPS Background Service Stops Receiving Updates
Thank you everyone for the replies. Here are my responses: I am holding the home button and the list of apps comes up and I swipe away my app to kill it. This is what others have mentioned above. I don't know if this is samsung only or not. Maybe this method is supposed to kill all running services and processes of the app and is not a good way to test. I tried giving the service a different process. I tried 2 things. First I just added the android:process tag to my service. I gave it a name with the ':' in front so it would be private to my app. This did not change anything. The service still dies when I kill the app. The other thing I noticed is when I go to the Settings - Application Manager - Running I see my app. If I tap on it to see what it is doing I get the following sections / information: Active App: MyApp 1 process and 1 service Services: MyService Start by application Processes: MyApp com.mycompany.myappspace:MyService Main process in use. So I decided to try adding the android:process section to the main application entry in the xml as well. I gave it a different name just in case. I called it MyApp instead of MyService. This did not make any difference. The information shown in the settings panel were the same. So am I to assume that the service is running in the same process as the app so that when I kill the app using the method above that is why the service is also dying? Is killing the app that way the wrong way to test? The whole reason I am doing this is because originally I just put my gps stuff inside the app itself. I would start my app and then many hours later I would enter the geofence area I had set up and the app did not trigger what I wanted it to do. I would go to the app and it looked like it was starting all over. Maybe I should just start my app and let it run for several hours and see if the service keeps going. Thanks for all the help. On Monday, November 24, 2014 7:58:36 AM UTC-7, Mukesh Srivastav wrote: As my understanding here, the service was stopped some where in the code and hence it is behaving like that. On Mon, Nov 24, 2014 at 7:38 PM, Mark Phillips ma...@phillipsmarketing.biz javascript: wrote: On my Samsung Galaxy 4 phone from T-Mobile, I can hold down the home button and get a list of running apps. I can kill each one individually with a swipe, and there is a trashcan icon at the bottom of the screen that will kill all the apps running. I use this feature to extend my battery time when the batter is getting low. It may be a special Samsung app that does this. Mark On Mon, Nov 24, 2014 at 1:13 AM, gjs garyjam...@gmail.com javascript: wrote: Hi, What do you mean by - ...I test this by holding down the home button and killing my app ? If I start an app, then press hold down the Home button, the app that was running is sent to the background (not killed) the only option that appears is a circle that pops up to run Google Now - if I then swipe upwards. There is no option to kill any apps via the Home button interaction you described as far as I know, I tested this on (stock) Nexus 5 with Android 5 as well as Sony Xperia 2 with Android 4.4 phone devices. The only (stock) standard way I know to kill apps is via Android Settings-Apps-Downloaded-(select App)-Press 'Force stop' button. I'd suggest you try in the service manifest entry android:exported=true if that is ok for your app. Other things to try are android:process also make sure you are using startForeground(..) stopForeground(.) calls in your service or it will be killed by the OS after a period of time and finally you probably need to use a wake lock to keep the CPU running when the display is turned off. I use these settings to get a GPS (background) Service to continue to run ok indefinitely after the uses exits my app or presses the home button or turns the screen off. (But be warned that these actions can deplete the device battery fairly quickly which many users do not like). The user can still always kill the app background service even when the app is stopped / service in the background via Android Settings-Apps-Downloaded-(select App)-Press 'Force stop', there is nothing your app can do to avoid this... Regards On Sunday, November 23, 2014 5:44:45 PM UTC+11, Tony Pitman wrote: I am writing an app that needs to get gps location information in the background. I created a class derived from Service to do this. I copied the example on the Android developer site about making a background service. It uses the ServiceHandler thread to do the work. I use location manager and set up the receiving of updates. I have my main activity create the service using the normal way like this: Intent intent = new Intent(_context, MyService.class); _context.startService(intent); Inside my service I create the location manager and start getting location updates. This works
Re: [android-developers] Re: GPS Background Service Stops Receiving Updates
It looks like calling startForeground was the key. I am still not able to kill the app using the method mentioned above, but at least now when I let the app sit for a long period of time the GPS notifications keep coming into the service even when it looks like the app has been shut down by the OS for lack of use. I do have another related question. When I did my service I was following the example of a service on the google dev site. This is the link to what I followed: http://developer.android.com/guide/components/services.html You will notice about the middle of the page there is the example code that I followed and then modified. They use a HandlerThread to create the Looper that gets used in the mServiceHandler thread to process the actual work. They pass in a parameter to that HandlerThread called Process.THREAD_PRIORITY_BACKGROUND. Is this different than using the startForeground that now fixed my issue? I left that HandlerThread the way it was and it now works with the startForeground. Thanks! On Monday, November 24, 2014 8:17:18 AM UTC-7, Tony Pitman wrote: Thank you everyone for the replies. Here are my responses: I am holding the home button and the list of apps comes up and I swipe away my app to kill it. This is what others have mentioned above. I don't know if this is samsung only or not. Maybe this method is supposed to kill all running services and processes of the app and is not a good way to test. I tried giving the service a different process. I tried 2 things. First I just added the android:process tag to my service. I gave it a name with the ':' in front so it would be private to my app. This did not change anything. The service still dies when I kill the app. The other thing I noticed is when I go to the Settings - Application Manager - Running I see my app. If I tap on it to see what it is doing I get the following sections / information: Active App: MyApp 1 process and 1 service Services: MyService Start by application Processes: MyApp com.mycompany.myappspace:MyService Main process in use. So I decided to try adding the android:process section to the main application entry in the xml as well. I gave it a different name just in case. I called it MyApp instead of MyService. This did not make any difference. The information shown in the settings panel were the same. So am I to assume that the service is running in the same process as the app so that when I kill the app using the method above that is why the service is also dying? Is killing the app that way the wrong way to test? The whole reason I am doing this is because originally I just put my gps stuff inside the app itself. I would start my app and then many hours later I would enter the geofence area I had set up and the app did not trigger what I wanted it to do. I would go to the app and it looked like it was starting all over. Maybe I should just start my app and let it run for several hours and see if the service keeps going. Thanks for all the help. On Monday, November 24, 2014 7:58:36 AM UTC-7, Mukesh Srivastav wrote: As my understanding here, the service was stopped some where in the code and hence it is behaving like that. On Mon, Nov 24, 2014 at 7:38 PM, Mark Phillips ma...@phillipsmarketing.biz wrote: On my Samsung Galaxy 4 phone from T-Mobile, I can hold down the home button and get a list of running apps. I can kill each one individually with a swipe, and there is a trashcan icon at the bottom of the screen that will kill all the apps running. I use this feature to extend my battery time when the batter is getting low. It may be a special Samsung app that does this. Mark On Mon, Nov 24, 2014 at 1:13 AM, gjs garyjam...@gmail.com wrote: Hi, What do you mean by - ...I test this by holding down the home button and killing my app ? If I start an app, then press hold down the Home button, the app that was running is sent to the background (not killed) the only option that appears is a circle that pops up to run Google Now - if I then swipe upwards. There is no option to kill any apps via the Home button interaction you described as far as I know, I tested this on (stock) Nexus 5 with Android 5 as well as Sony Xperia 2 with Android 4.4 phone devices. The only (stock) standard way I know to kill apps is via Android Settings-Apps-Downloaded-(select App)-Press 'Force stop' button. I'd suggest you try in the service manifest entry android:exported=true if that is ok for your app. Other things to try are android:process also make sure you are using startForeground(..) stopForeground(.) calls in your service or it will be killed by the OS after a period of time and finally you probably need to use a wake lock to keep the CPU running when the display is turned off. I use these settings to get a GPS (background) Service to continue to run ok indefinitely after the uses exits my
Re: [android-developers] Re: GPS Background Service Stops Receiving Updates
On Mon, Nov 24, 2014 at 9:17 AM, Tony Pitman t...@shatalmic.com wrote: The whole reason I am doing this is because originally I just put my gps stuff inside the app itself. I would start my app and then many hours later I would enter the geofence area I had set up and the app did not trigger what I wanted it to do. I would go to the app and it looked like it was starting all over. A little late to this party, but ... If you're after geo-fencing, see here: http://developer.android.com/training/location/geofencing.html If you want to do stuff in response to location changes while your app is not active, use this: http://developer.android.com/reference/android/location/LocationManager.html#requestLocationUpdates%28long,%20float,%20android.location.Criteria,%20android.app.PendingIntent%29 On Mon, Nov 24, 2014 at 2:29 PM, Tony Pitman t...@shatalmic.com wrote: They pass in a parameter to that HandlerThread called Process.THREAD_PRIORITY_BACKGROUND. Is this different than using the startForeground that now fixed my issue? Yes, the thread priority is for the system to manage and schedule threads. This relates to* time and frequency allocation* for threads to run. startForeground is specifically to mark a Service object as being important to a user's experience, such that the system will favor it when memory gets tight. The system will kill other components (background services, Activities no longer visible, etc) before killing a foreground service. This relates to *memory allocation* for system resources. - TreKing http://sites.google.com/site/rezmobileapps/treking - Chicago transit tracking app for Android-powered devices -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en --- You received this message because you are subscribed to the Google Groups Android Developers group. To unsubscribe from this group and stop receiving emails from it, send an email to android-developers+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.