Android Question Closing Notification If App Is Killed

HimeAnator

Member
Licensed User
Longtime User
I created an app that upon pressing a start button the app then creates a notification letting the user know the app is running. I noticed however that if the user were to kill the application by swiping it away in the task bar then the notification is not closed. Is there a way to cancel the notification if the app is closed altogether? I still want the user to have the ability to leave my app such as go to home the screen and leave it running in the background, I just want cancel the notification only if the app have been totally closed. Can I somehow check if the app closed from the service running my notification and if so then cancel it?
 

KZero

Active Member
Licensed User
Longtime User
-i think the notification should be canceled automatically if the app closed
however you can try to cancel it manually before closing the app
B4X:
n.OnGoingEvent =False

n.cancel(ID)

- swiping the notification away will not close the application

-you can check if an activity is active or paused using
B4X:
IsPaused
 
Upvote 0

HimeAnator

Member
Licensed User
Longtime User
Thank you for the reply KZero, basically what I'm trying to do is detect if the app has been killed from the task manager. My app performs calculations in the background so I'm ok with the user having the ability to tap the home or back button to go to their home screen or something like that while the app is still open in the background. The problem is if the user forces my app to close by killing it in the task manager then the app and background calculations cease and they are still left with a notification saying that the app is running when actually its not. When the user kills an app that way I don't think any of the events are triggered, the app is just stopped dead in its tracks. If the user causes the application to pause that is fine, my calculations are still performed. I'm trying to detect whether the app has been closed altogether. Thinking this needs to be done in the notification service module :/
 
Upvote 0

DT1111

Member
Licensed User
Longtime User
HimeAnator, I have a similar situation and I am curious if you have had closure or solution to the above issue?
 
Upvote 0
Top