Android Question Activity recognition stops working when closing the app

Almog

Active Member
Licensed User
Hi there!

I tried to build a sample app that notifies (using nb6) when the current user physical activity changes (using physical-activity-recognition-detection library).

It worked, but after closing the app with the user's 'task manager' (where you 'swipe' apps to stop them), I stopped getting notifications about the current user physical activity...

Does anybody know why does it happen? Is there a way to improve it to work even when the app is closed?

Thanks in advance
 

MarkusR

Well-Known Member
Licensed User
Longtime User
When a app is killed then all services of this app are killed also as the services are part of the process. The process is killed.
.
The answer is NO.

after pressung □ and swipe out my app a extra foreground service will stay. i can get his data from process global after i start the app again. at least with my android 8.x device.
 
Upvote 0

Almog

Active Member
Licensed User
On my code Activity_Pause is empty, so the ActivityRecognition will not stop when exiting the app..
 
Upvote 0

MarkusR

Well-Known Member
Licensed User
Longtime User
but it can happen that android remove the Activitys, its like ms windows would close your app windows.

this object +Initialize +Events should move from the activity to your extra foreground service.
B4X:
 Public ar As ActivityRecognition
 
Upvote 0

Almog

Active Member
Licensed User
As you said, I moved:
B4X:
Public ar As ActivityRecognition
and
B4X:
ar.Initialize("ar")
ar.Connect(5000)
to the RecognitionService service, and it worked! Thank you very much!

I now understand that when Main activity is closed, 'ar' object does not exist anymore, that's why you told me to move it
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…