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 (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-d...@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-d...@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.
>>>>
>>>
>>>
>>>
>>> -- 
>>> Warm Regards,
>>> *Mukesh Kumar*,
>>> Android Consultant/Freelancer,
>>> India,Hyderabad.
>>>  
>>

-- 
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