Android Question how to stop a ForeGroundService after application/activity is closed

wmardian

Member
Licensed User
Longtime User
Dear All,
I have an activity that start a service by clicking button.
Could you please advice how to:

1. Stop a ForeGround service after the application is closed by sliding the application in recent app list on android 4.2.1.
How to call stopForeground, where should i put the "stopForeground", and how to trigger it. I have been trying to re-open the application (from home), and click stop button and put stopForeground(Id of notification), but it fail.

2. is it possible to trap "datetime.now = target-time" in running service?

Thanks in advance
Best Regards
 

wmardian

Member
Licensed User
Longtime User
Dear Erel, and all B4A users
Many thanks for your respond. Please help for these;
1. Is it possible to close the foreground service in certain time, or by clicking button event.
2. If we use a timer, is it possible to do something in exact time, by using folowing code:

B4X:
If  DateTime.Now  = target_time_as_long Then
        'do something important
End If

I have tried to use above code and did not work. But if i use following code, for usual service (not forground service), it works.
B4X:
If  DateTime.Now  > target_time_as_long Then
        'do something important
End If

But i do not want the second one, i need exact time to do something

3. How do we call or interact with foreground service, after we close the activity/the app.

Please help me to answer those 3 question. Already tried to find in all posts but still no luck. Your help is very appreciated
Thanks in advance
Best Regards
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…