Android Question Simple Watchdog not working

Jack Howard

Member
Licensed User
Longtime User
My App using Camera2 occasionally crashes by going into Activity_Pause.

I have created a watchdog attached, but I cannot get the activity to restart or resume.

I have included MANAGE_OVERLAY_PERMISSION and also added it to the manifest, that part is working.

The timer is also working as it is only enabled when Activity is paused.

I seem to be failing in the timer to recover the situation.

The watchdog project is included.

B4X:
Sub Watchdog_Tmr_Tick
    'Main.Crashed=Main.Crashed+1
    
    'If Main.Crashed>3 Then
        Log("Watchdog_Tmr_Tick")
        CallSubDelayed("Main","Activity_Resume")
        Watchdog_Tmr.Enabled=False
        'CallSubDelayed("Starter","Service_Start")
    'CallSubDelayed("Main","Activity_Create")
    'CallSubDelayed("Main","Boot")

    'End If
End Sub
 

Attachments

  • Watchdog.zip
    475.5 KB · Views: 237
Last edited:

DonManfred

Expert
Licensed User
Longtime User
I dont think that you can force your own app to reappear if one exit your app using the back or homebutton. Probably it is Android who prevent this.

I did used backbutton.

The main goes to pause, the watchdog timer in starter is started.

then the timer ticks and your service tries to start the activity using callsubdelayed which is ignored as the app is paused.

The point is that the user quits the app. Android prevent the starting of your app i guess.

Edit to add: I did not used any Watchdog in the past. So i am not talking with experience. I may be wrong.

The request for the watchdog permission is asked and i allowed it. So the problem seems to be something other.
 
Upvote 0

Jack Howard

Member
Licensed User
Longtime User
I dont think that you can force your own app to reappear if one exit your app using the back or homebutton. Probably it is Android who prevent this.

I did used backbutton.

The main goes to pause, the watchdog timer in starter is started.

Thank you very much for looking at my code,

I was inspired by Erel:
You can call "StartActivity" from a service after several seconds.
https://www.b4x.com/android/forum/t...-foreground-after-starting-another-app.21095/

Weird thing is I cant find a sub called "StartActivity" despite others on the forum mentioning it, which is why I tried the others that are remmed out one at a time
 
Upvote 0

Jack Howard

Member
Licensed User
Longtime User
StartActivity is a keyword.
B4X:
StartActivity(Main)

Thanks for the StartActivity info. I am still stuck why my Watchdog cannot recover from a crash.

Is there something wrong with CallSubDelayed("Main","Activity_Resume")

It seems the crash causes the APP to go into Pause. Is there any other way to stop this, or recover from pause without the user tapping on the APP to bring it back.

This suggests it can be done
You can call "StartActivity" from a service after several seconds.
https://www.b4x.com/android/forum/t...-foreground-after-starting-another-app.21095/

If it is not possible, is it possible in any way that a separate APP could be a watchdog, restarting a APP that crashes into Pause
 
Upvote 0
Top