Click here to Skip to main content
15,795,789 members
Please Sign up or sign in to vote.
3.67/5 (3 votes)
See more:
Hi,

to be more precise, than the title says:
I am working on a SIP App which uses a "sticky" Service when starting to boot the Sip stack and to keep it alive even when the app is in background for a long time and even when Android starts purging things when resources get low.
minApi Level is 15.

My technical Problem is this:
- Can I somehow "detect" when the user closes the app from the open-apps-list with a swipe? Or is this a simple and plain "kill" of my app's process and there is no available hook to perform some last action before getting killed?

What I need to achieve is:
- Service stays active all the time, no matter whether the app is in foreground or background and no matter for how long it stays there.
- The App must not be "exited" when pressing the back button on the main activity (dialer) - this is by requirement of the product owners - that part is solved.
BUT... - and here starts my problem:
- When the user is "killing" the app (i.e. swipe from the app list), the sip stack shall perform a shutdown and the user is "not available" via sip - i.e. "offline". Technical for my app, this means: Shutdown Sip / Stop the sticky service.

What approach to take here?

Thanks for any tipps, this is driving me crazy.
cheers, Mike
Posted
Updated 1-Jan-16 0:25am
v2
Comments
Afzaal Ahmad Zeeshan 1-Jan-16 5:42am    
Interesting question, doesn't onDestory() help you in what you want to achieve? The function is executed when application is destroyed. I never tried it to test the swiping removal, but maybe it can help you.
Mike (Prof. Chuck) 1-Jan-16 6:16am    
Thanks for the quick reply :)
Unfortunately onDestroy on the Main activity does not help - it even gets called whenever Android thinks, it needs resources.
I need the point, where the "user" takes a "conscious action" of killing the app *now*.
I am not really sure, if this is possible in a way the product owners want it.

onDestroy() and onStop() wouldn't be fired if app is closed from recent apps list or killed by android system. But there may be a workaround like these:

How to handle code when app is killed by swiping in android? - Stack Overflow[^]
android - How to detect app removed from the recent list - Stack Overflow[^]
 
Share this answer
 
Comments
Mike (Prof. Chuck) 3-Jan-16 12:11pm    
This looks like what I have been searching for - onTaskRemoved - didn't know the manifest flag so far - thank you very much!
ridoy 3-Jan-16 12:48pm    
Thank you!
Not sure if you can get what you are asking but Activity | Android Developers[^] shows the various callbacks you can use.
 
Share this answer
 
I am not sure if it will work by can't you make the startForeground. Just make sure you START_STICKY in the onStartCommand. It will still kill the service but it should automatically start the service once again after a few seconds. Hopefully what I said helps you out.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900