Android Question how to set app as always active - don't pause when another app goes foreground

vangogh

Active Member
Licensed User
Longtime User
My app has a counter, counting seconds

semplified code [cut]

timer:
Sub Process_Globals
    Dim tmrTimerIndirizzoIP As Timer
end sub

Sub Activity_Create(FirstTime As Boolean)
    tmrTimerIndirizzoIP.Initialize("tmrTimerIndirizzoIP", 1000)
    tmrTimerIndirizzoIP.Enabled=True
end sub

Sub Activity_Resume
    Log("RESUME")
end Sub

Sub Activity_Pause (UserClosed As Boolean)
    Log("IN PAUSA")
End Sub

Sub tmrTimerIndirizzoIP_Tick()
    Log(DateTime.Date(DateTime.now) & " tick")
end sub


if the app in sent in backgound, e.g I open a another app, or the screen saver is active, the app goes to sleep - freezing. the timer stops running
(the Activity_pause sub is colled)

and it resume counting when the app is in foregroud again
(the Activity_resume sub is called)

see attacked image: it's the log

I saw PhoneWakeState, but it does different things (?)

SO:
How can I set the app to continue running also if another app in in foregroud, also if the screen goes off?
I need that my app is always active and doing his job - NO pause

thank you
 

Attachments

  • Image2.jpg
    Image2.jpg
    75.1 KB · Views: 31

JohnC

Expert
Licensed User
Longtime User
You can't have an "Activity" run in the background, but you can have a "Service" run in the background.

Here is a sample project on how to do that:


NOTE: Newer versions of Android have more restictions on what can run in the background.
 
Upvote 0
Top