C Christian321 Member Licensed User Longtime User Dec 2, 2016 #1 Dear All, willing to program a software for my little daugther I am facing the following problem: My kid always manages to send my app to the background. She does not know what she is doing, thus presses all buttons including 'back' and 'home'. Aware of the fact that this drains the battery I want my B4A application to stay upfront no matter what happens. Therefore I tried two ways: (1) In the Main activity: Sub Activity_Pause (UserClosed As Boolean) StartActivity(Me) End Sub (2) In the Starter service: Sub Process_Globals Dim myWatchdogTimer As Timer Dim KeepServiceRunning As Boolean = True End Sub Sub Service_Create myWatchdogTimer.Initialize("CheckMainForeground", 300) myWatchdogTimer.Enabled = True End Sub Sub CheckMainForeground_Tick If KeepServiceRunning = True And IsPaused(Main) Then StartActivity(Main) End Sub Both ways work well with the back button, however when I press the home button it takes seconds to bring back my application to foreground. Enough time for my kid to do other weird thing to my phone. I am sure there is a better way to force the activity to stay. By any chance, maybe without having to restart the main activity each time? And yes, it would be ideal if the screen stayed always-on... Many thanks for your help in advance, Christian
Dear All, willing to program a software for my little daugther I am facing the following problem: My kid always manages to send my app to the background. She does not know what she is doing, thus presses all buttons including 'back' and 'home'. Aware of the fact that this drains the battery I want my B4A application to stay upfront no matter what happens. Therefore I tried two ways: (1) In the Main activity: Sub Activity_Pause (UserClosed As Boolean) StartActivity(Me) End Sub (2) In the Starter service: Sub Process_Globals Dim myWatchdogTimer As Timer Dim KeepServiceRunning As Boolean = True End Sub Sub Service_Create myWatchdogTimer.Initialize("CheckMainForeground", 300) myWatchdogTimer.Enabled = True End Sub Sub CheckMainForeground_Tick If KeepServiceRunning = True And IsPaused(Main) Then StartActivity(Main) End Sub Both ways work well with the back button, however when I press the home button it takes seconds to bring back my application to foreground. Enough time for my kid to do other weird thing to my phone. I am sure there is a better way to force the activity to stay. By any chance, maybe without having to restart the main activity each time? And yes, it would be ideal if the screen stayed always-on... Many thanks for your help in advance, Christian
P panagiotisden2 Active Member Licensed User Longtime User Dec 2, 2016 #2 what is your timer's interval? Upvote 0
C Christian321 Member Licensed User Longtime User Dec 2, 2016 #3 panagiotisden2 said: what is your timer's interval? Click to expand... 300ms I suppose... myWatchdogTimer.Initialize("CheckMainForeground", 300) My Starter service is sticky, by the way: #StartCommandReturnValue: android.app.Service.START_STICKY Upvote 0
panagiotisden2 said: what is your timer's interval? Click to expand... 300ms I suppose... myWatchdogTimer.Initialize("CheckMainForeground", 300) My Starter service is sticky, by the way: #StartCommandReturnValue: android.app.Service.START_STICKY
P panagiotisden2 Active Member Licensed User Longtime User Dec 2, 2016 #4 try to remove the Code: And IsPaused(Main) in the timer code. Maybe there is a delay to show the activity as paused Upvote 0
try to remove the Code: And IsPaused(Main) in the timer code. Maybe there is a delay to show the activity as paused
P panagiotisden2 Active Member Licensed User Longtime User Dec 2, 2016 #5 also you can use this in the main activity so the app wont exit when the back button is pressed Code: Sub Activity_KeyPress (KeyCode As Int) As Boolean If KeyCode = KeyCodes.KEYCODE_BACK Then 'do nothing End If End Sub Upvote 0
also you can use this in the main activity so the app wont exit when the back button is pressed Code: Sub Activity_KeyPress (KeyCode As Int) As Boolean If KeyCode = KeyCodes.KEYCODE_BACK Then 'do nothing End If End Sub
C Christian321 Member Licensed User Longtime User Dec 2, 2016 #6 panagiotisden2 said: try to remove the Code: And IsPaused(Main) in the timer code. Maybe there is a delay to show the activity as paused Click to expand... I did try. Funny story, indeed my app stays in front now, but no events will be handled at all any more. Including my Rescue-"End"-Button. Now the app is too sticky, even itself cannot finish. Upvote 0
panagiotisden2 said: try to remove the Code: And IsPaused(Main) in the timer code. Maybe there is a delay to show the activity as paused Click to expand... I did try. Funny story, indeed my app stays in front now, but no events will be handled at all any more. Including my Rescue-"End"-Button. Now the app is too sticky, even itself cannot finish.
C Christian321 Member Licensed User Longtime User Dec 2, 2016 #7 panagiotisden2 said: also you can use this in the main activity so the app wont exit when the back button is pressed Code: Sub Activity_KeyPress (KeyCode As Int) As Boolean If KeyCode = KeyCodes.KEYCODE_BACK Then 'do nothing End If End Sub Click to expand... I tried this, too. No change. However, the back-button isn't big a problem. Pressing back the Activity_Pause --> StartActivity(Main) works well. It is the home-button that gives me the trouble. But many, many thanks for your thoughts anway! Upvote 0
panagiotisden2 said: also you can use this in the main activity so the app wont exit when the back button is pressed Code: Sub Activity_KeyPress (KeyCode As Int) As Boolean If KeyCode = KeyCodes.KEYCODE_BACK Then 'do nothing End If End Sub Click to expand... I tried this, too. No change. However, the back-button isn't big a problem. Pressing back the Activity_Pause --> StartActivity(Main) works well. It is the home-button that gives me the trouble. But many, many thanks for your thoughts anway!
P panagiotisden2 Active Member Licensed User Longtime User Dec 2, 2016 #8 Christian321 said: I did try. Funny story, indeed my app stays in front now, but no events will be handled at all any more. Including my Rescue-"End"-Button. Now the app is too sticky, even itself cannot finish. Click to expand... isn't this what you want? even you cant stop it, your daughter wont even have a chance in main activty add a button Code: sub button1_click callsub(starter,"stopwatchdogs") end sub and in the starter Code: sub stopwatchdogs stopservice(me) end sub and make the timer's interval 1000ms(1 sec) note that the service might lead to a battery drain Upvote 0
Christian321 said: I did try. Funny story, indeed my app stays in front now, but no events will be handled at all any more. Including my Rescue-"End"-Button. Now the app is too sticky, even itself cannot finish. Click to expand... isn't this what you want? even you cant stop it, your daughter wont even have a chance in main activty add a button Code: sub button1_click callsub(starter,"stopwatchdogs") end sub and in the starter Code: sub stopwatchdogs stopservice(me) end sub and make the timer's interval 1000ms(1 sec) note that the service might lead to a battery drain
C Christian321 Member Licensed User Longtime User Dec 2, 2016 #9 Too bad and I feel really sorry, but still, as long as I use CheckMainForeground_Tick --> If KeepServiceRunning = True Then StartActivity(Main) all my events won't be handled any more, including "_click". Even with a timer interval of 1s: myWatchdogTimer.Initialize("CheckMainForeground", 1000) And I tried hard to end this: Sub Button1_Click CallSub(Starter,"stopwatchdogs") StopService(Starter) ExitApplication End Sub I suppose, starting the activity repetetively in short intervals uses too many ressources. And I start having the feeling that this brutal method isn't the right way, anyway. Upvote 0
Too bad and I feel really sorry, but still, as long as I use CheckMainForeground_Tick --> If KeepServiceRunning = True Then StartActivity(Main) all my events won't be handled any more, including "_click". Even with a timer interval of 1s: myWatchdogTimer.Initialize("CheckMainForeground", 1000) And I tried hard to end this: Sub Button1_Click CallSub(Starter,"stopwatchdogs") StopService(Starter) ExitApplication End Sub I suppose, starting the activity repetetively in short intervals uses too many ressources. And I start having the feeling that this brutal method isn't the right way, anyway.
udg Expert Licensed User Longtime User Dec 3, 2016 #10 Did you try the "kiosk mode" set up? I never used it but it sounds promising... udg Upvote 0
C Christian321 Member Licensed User Longtime User Dec 3, 2016 #11 Hi udg, I tried the kiosk mode example. In fact, I see the same behavior similar to my approach. In my case even just putting Code: Sub Activity_Pause (UserClosed As Boolean) StartActivity(Me) End Sub shows the exact same behavior. But many thanks anyway. Update: The KioskAppExtended does the job. Very complex solution but working. Thanks for the hint... Last edited: Dec 3, 2016 Upvote 0
Hi udg, I tried the kiosk mode example. In fact, I see the same behavior similar to my approach. In my case even just putting Code: Sub Activity_Pause (UserClosed As Boolean) StartActivity(Me) End Sub shows the exact same behavior. But many thanks anyway. Update: The KioskAppExtended does the job. Very complex solution but working. Thanks for the hint...
C Christian321 Member Licensed User Longtime User Dec 3, 2016 #12 Problem solved: See Android "Kiosk mode" tutorial Upvote 0