Android Question Mylocation example pauses

grafsoft

Well-Known Member
Licensed User
Longtime User
Hi,

I am using the example in https://www.b4x.com/android/forum/threads/background-location-tracking.99873/#content. I added the required line to my manifest.

The app pauses when the screen turns black.

I did not change a thing besides that I added a SQL table that holds some data and when clicking at "show table" you should see them in reverse order.

It is easy to see that when the screen is black for 1 minute you have lost that data, turning the screen on again the data is collected again.

Maybe I should not put the SQL in Process_Globals of the tracker unit? What am I doing wrong?
 

Attachments

  • MyLocation_.zip
    11.9 KB · Views: 157

grafsoft

Well-Known Member
Licensed User
Longtime User
Thank you

I did that, this is the log (my comments starting with ' )

*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
*** Service (tracker) Create ***
** Service (tracker) Start **
Timer : 18:09:53
Locationchanged: 18:09:54
Timer : 18:09:54
Locationchanged: 18:09:55

' ...
' Screen goes black, I wait a little

Locationchanged: 18:10:45
Timer : 18:10:45
Locationchanged: 18:10:46
** Activity (main) Pause, UserClosed = false **
Locationchanged: 18:10:47
** Service (starter) Destroy (ignored)**
** Service (tracker) Destroy **

I try to force a restart, add 1 line:

B4X:
Sub Activity_Pause (UserClosed As Boolean)
    If (UserClosed=False) Then Activity_Resume
End Sub

Locationchanged: 18:28:51
Timer : 18:28:51
** Activity (main) Pause, UserClosed = false **
sending message to waiting queue (activity_permissionresult)

' I restart the screen and look at the table

** Activity (tabelle) Create, isFirst = false **
** Activity (tabelle) Resume **
Locationchanged: 18:28:52
Locationchanged: 18:28:53
Locationchanged: 18:28:54
Locationchanged: 18:28:55
Locationchanged: 18:28:56
Locationchanged: 18:28:57
Locationchanged: 18:28:58
Locationchanged: 18:28:59
Locationchanged: 18:29:00
Locationchanged: 18:29:01
Locationchanged: 18:29:02
Locationchanged: 18:29:03
Locationchanged: 18:29:04
Locationchanged: 18:29:05
Locationchanged: 18:29:06
Locationchanged: 18:29:07
Locationchanged: 18:29:08
Locationchanged: 18:29:09
Locationchanged: 18:29:10
Locationchanged: 18:29:11
Locationchanged: 18:29:12
Locationchanged: 18:29:13
Locationchanged: 18:29:14
Locationchanged: 18:29:15
** Activity (tabelle) Pause, UserClosed = true **
running waiting messages (1)
** Activity (main) Resume **
** Service (tracker) Start **
** Service (tracker) Start **
Locationchanged: 18:29:16
Timer : 18:29:16
Locationchanged: 18:29:17
Timer : 18:29:17
Locationchanged: 18:29:18
Timer : 18:29:18

' ...

Timer : 18:29:49
Locationchanged: 18:29:50
Timer : 18:29:50
Locationchanged: 18:29:51
** Activity (main) Pause, UserClosed = false **

' log stops. I wake up the screen

sending message to waiting queue (activity_permissionresult)
Locationchanged: 18:29:52
running waiting messages (1)
** Activity (main) Resume **
** Service (tracker) Start **
** Service (tracker) Start **
Timer : 18:30:39
Timer : 18:30:40
Locationchanged: 18:30:41
Timer : 18:30:41
Locationchanged: 18:30:42

So ... with this change the system restarts as soon as the screen is not black and I have logged in on my cell. But this is not enough, think of all the fitness trackers which run all the time during a session, black or not.

Can I try something else?
 
Upvote 0

grafsoft

Well-Known Member
Licensed User
Longtime User
This is strange. Are you somewhere in your code stopping the tracker service? As it is a foreground service it shouldn't be destroyed.
Definitely not. I switched to your original example and only added the log function.

Timer : 12:41:03
Locationchanged: 12:41:04
Timer : 12:41:04
Locationchanged: 12:41:05
Timer : 12:41:05
Locationchanged: 12:41:06
Timer : 12:41:06
** Activity (main) Pause, UserClosed = false **
Locationchanged: 12:41:07
** Service (starter) Destroy (ignored)**
** Service (tracker) Destroy **
 
Upvote 0

grafsoft

Well-Known Member
Licensed User
Longtime User
Super, you got the answer!

"

Battery optimization​

To keep your apps working properly make sure you enable:
Settings -> Apps -> Your App -> Battery -> Battery optimization -> All apps -> Your app -> Don’t optimize.
"

Below the protocol.

Big thanks!

Peter


*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
*** Service (tracker) Create ***
** Service (tracker) Start **
Timer : 16:43:53
Timer : 16:43:54
Locationchanged: 16:43:55
Timer : 16:43:55
Locationchanged: 16:43:56
Timer : 16:43:56
Locationchanged: 16:43:57
Timer : 16:43:57

' ...

Timer : 16:44:41
Locationchanged: 16:44:42
Timer : 16:44:42
Locationchanged: 16:44:43

' screen goes black, timer pauses because it is in main activity

** Activity (main) Pause, UserClosed = false **
Locationchanged: 16:44:44
Locationchanged: 16:44:45
Locationchanged: 16:44:46

...

Locationchanged: 16:46:24
Locationchanged: 16:46:25
Locationchanged: 16:46:26
Locationchanged: 16:46:27
Locationchanged: 16:46:28
Locationchanged: 16:46:29
Locationchanged: 16:46:30

' I wake the screen up and log in

** Activity (main) Resume **
Timer : 16:46:30
** Service (tracker) Start **
Locationchanged: 16:46:31
Timer : 16:46:31
Locationchanged: 16:46:32
Timer : 16:46:32
Locationchanged: 16:46:33
Timer : 16:46:33
 
Last edited:
Upvote 0
Top