Check application if is running

brelto85

Active Member
Licensed User
Longtime User
I've a service in background that check if the application is running to do some operation but using the IsPause method doesn't work as expected.
In fact if is executing the voicerecognition, the activity is InPause

is there a way to check if application is running (not using IsPause method) controlling the process?
 

brelto85

Active Member
Licensed User
Longtime User
I try to explain the scenario:

When start my app, sets the audio settings (mode normal, max level volume ecc..) to enable better management of the voice recognition.
When i close the application with back button, resets the audio settings

The problem is how to reset settings if the user close application with home button.
I thought of a service (which starts when the application starts) that every second checks if the application is active or not. If not (IsPause(MainActivity)) resets the audio settings.
As mentioned before, the method IsPause is not reliable when in action the voice recognition

I would like to know if there another way to check if application is active or not
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
The problem is that in Android there isn't really a point where your application reaches its end (unless you create an "Exit" button).

The simplest solution is to set the audio settings in Activity_Resume and reset them in Activity_Pause. If however you also need the custom settings when the voice recognition dialog is visible then you should use the service and check whether the activity is paused after 30 seconds.
 
Upvote 0

SoyEli

Active Member
Licensed User
Longtime User
This may help:

sub CheckPackage(Package as string)
Dim sb As StringBuilder
sb.Initialize
Phone.Shell("ps", Null, sb, Null)
Dim m As Matcher
m = Regex.Matcher2("^[^ ]*\s+(\d+) .*" & Package, Regex.MULTILINE, sb.ToString)
If m.Find Then
Log(Package & " is running")
Return True
Else
Log(Package & " is NOT running")
Return False
End If
end sub
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…