Get all tasks

Neojoy

Member
Licensed User
Longtime User
Hi,

I would like to know, how can I get all tasks using android.permission.GET_TASKS
 

Neojoy

Member
Licensed User
Longtime User
I did an app using OS and Phone librarys and works fine, but KillBackgroundProcesses and killProcess doesn't works, any idea?

Thanks Martin
 
Upvote 0

warwound

Expert
Licensed User
Longtime User
I did an app using OS and Phone librarys and works fine, but KillBackgroundProcesses and killProcess doesn't works, any idea?

Thanks Martin

I think it's because a standard (non-system) android app simply isn't supposed or expected to perform such tasks.

As i mentioned in the thread where i posted the ActivityManager i said it was unreliable and unpredictable.
Maybe i should have said that mostly it simply does not work!
When testing i found it would successfully kill an app process as long as that app was paused - in the background.
I then needed to kill the same app process while it was not paused - it was the running foreground app.
This never worked, so i tried using an Intent to start the device's launcher app and then killing the app process as it was now paused and in the background.
This always failed so i tried using a Timer with a long delay to give the system plenty of time to start the launcher and allow for the app to go into the background.
Even with long (30 seconds i think) delays it mostly failed.

To be honest there was no predicting if killing a process would succeed or not, whether the app was in the background or foreground made little difference.
It might work and it might not.

Executing an adb shell command worked without fail so became our solution.
The adb commands were put together by someone else so i can't recall exactly what to do there - if you want me to find out the commands let me know.

Martin.
 
Upvote 0

Neojoy

Member
Licensed User
Longtime User
I would like so much if you show me the way to use "adb shell command", if OS can kill an app quickly is because exists one way

Thanks
 
Upvote 0

ericvanderhoeven

Member
Licensed User
Longtime User
ADB commands to kill a foreground task

I would like so much if you show me the way to use "adb shell command", if OS can kill an app quickly is because exists one way

Thanks

Hi,

here is what I ended up doing, trying to figure it all out with Martin..

It isn't pretty but it works.

First you define the terminal-command sub, which uses Stringbuilder. This sub is your vehicle to issue what I call terminal commands =

B4X:
Sub terminalcommando(commando As String)
   Dim Command, Runner As String
   Dim StdOut, StdErr As StringBuilder
   Dim Result As Int

    Runner = File.Combine(File.DirInternalCache, "runner")
    Command = File.Combine(File.DirInternalCache, "command")
    File.WriteString(File.DirInternalCache, "runner", "su < " & Command)
    File.WriteString(File.DirInternalCache, "command", commando & CRLF & "exit") 'Any commands via crlf, and exit at end 
    StdOut.Initialize
    StdErr.Initialize
    Result = ph.Shell("sh", Array As String(Runner), StdOut, StdErr)
End Sub

Then you do the killing where appropriate =

B4X:
terminalcommando("busybox killall uk.co.aifactory.solitairefree")


Where uk.co.aifactory.solitairefree is the package name of the app you want to kill (in this case Solitaire...)
This kill however kills only the current ACTIVITY and is similar to the BACK button of Android so in case you have more activities stacked, count the max possible stacked activities for the app and issue the above command this amount of times.

I do this with a simple timer/wait cycle after each kill command. In my case, a timer of 250ms ( JustDelay.Initialize("JustDelay", 250) )
was enough and I issue this command 3 times =

B4X:
terminalcommando("busybox killall uk.co.aifactory.solitairefree")
waitXseconds
Do While Justwaiting
   DoEvents
Loop

terminalcommando("busybox killall uk.co.aifactory.solitairefree")
waitXseconds
Do While Justwaiting
   DoEvents
Loop

terminalcommando("busybox killall uk.co.aifactory.solitairefree")
waitXseconds
Do While Justwaiting
   DoEvents
Loop

Of course, you need to define these =
B4X:
Sub waitXseconds

   JustDelay.Enabled = True
   Justwaiting = True
   
End Sub

Sub JustDelay_tick

   JustDelay.Enabled = False
   Justwaiting = False
   
End Sub

That should do it.

Eric
 
Upvote 0

Neojoy

Member
Licensed User
Longtime User

I'll try your code, thanks a lot

Hi Eric, I don´t know what´s wrong, but doesn´t work, I did exactly as your code but app still running.

Any idea?
 
Last edited:
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…