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.

Reply via email to