Page 1 of 1

App starting triggerd both start and end, why?

Posted: 05 Dec 2019 04:05
by jassing
Why does starting an app (or tapping the shortcut to switch to already running app) result in triggering both start and stop events?

Attached is dirt simple flow... Launch maps or waze.

Re: App starting triggerd both start and end, why?

Posted: 05 Dec 2019 04:20
by Desmanto
Of course it will be so. This is working as expected, not a bug.

When the flow triggered after opening maps, debug dialog appear. Android OS now shift the foreground app to Automagic (because debug dialog belongs to automagic), hence creating new event that maps has been ended (shifted to background). This triggered another debug dialog waiting to be shown. As soon as you close the debug dialog, the end trigger execution show another debug dialog. But during the split milisecond, the map become the foreground again, and trigger another flow execution, preparing another debug dialog again. This loop until you quickly press back to escape from the infinite trigger. (Or you hit AEP)

The proper solution to this is to change the FEP (Flow Execution Policy) to "skip" and add at least 500ms sleep at the end of the flow. In this case, add it both yes no path of the debug dialog. 500ms depends on the phone, it can be lower or higher, need to be tested.

Any dialog type action/condition will cause this interference with app task started/ended, because it is the way android dialog works. Input Dialog, Input Speech (with user interface), Message Dialog, Confirmation Dialog, Debug Dialog and Biometric Dialog.

Re: App starting triggerd both start and end, why?

Posted: 05 Dec 2019 05:39
by jassing
Thanks. (I never claimed it was a bug, I was asking why it happened).

So task started is a misnomer, it is really app task focus?

Thank you for the explanation

Re: App starting triggerd both start and end, why?

Posted: 05 Dec 2019 10:37
by Desmanto
Oh, sorry. It seems I am rephrasing my old post/though from somewhere in the past, where I thought it is a bug. Somewhere older than this post : http://automagic4android.com/forum/view ... f=5&t=7605

The action name was correct. I remember when using them in Lollipop, it is working as expected. Any dialog from Automagic will be counted as floating overlay, and didn't trigger App Task Started/Ended. I jump from LP 5.1 to Oreo 8.1, and in Oreo, the behaviour started to change. Any dialog now started to trigger them. So at least the changes happen since Oreo.

Martin can't change the element naming once it has been official. Because a lot of users already using them. Changing the name might breaks a lot of users' flow. That's why we request for new action instead here : http://automagic4android.com/forum/view ... f=4&t=8083

Re: App starting triggerd both start and end, why?

Posted: 05 Dec 2019 17:06
by jassing
Thanks. So, is there a way to tell if an app was really started?

Re: App starting triggerd both start and end, why?

Posted: 06 Dec 2019 10:48
by Desmanto
Current trigger app task started is already working as we want. It already really reflect when the app is started. It is app task ended that has problem with notification, recent and dialog from other app. If you don't need direct feedback after app is closed, you can add sleep 5 seconds to the app task ended part and then check again if the app is running. If yes, then do nothing. If no, only then execute the ended branch. This 5 seconds work as a buffer before execute the main end branch.

Re: App starting triggerd both start and end, why?

Posted: 07 Dec 2019 01:05
by jassing
I hear you that the trigger works the way you want...

It is, however, (for me) it is firing whenever it receives focus. (using only app start trigger) the app is still active, but triggers again if it loses focus, and gets it back...

Thanks, I'll figure out something, I was just hopeful to get help... I'll assume the issue is unique to my devices, and find a work around.

Have a good weekend.

Re: App starting triggerd both start and end, why?

Posted: 07 Dec 2019 02:36
by Desmanto
The focus is the problem I mean with the task ended. Everytime you shift focus to other app and back to the app again, it triggers again. You have to put buffer to the flow to detect this quick changes in the focus.

At some samsung devices/ROM, when the focus is back to the app, app task started is not triggering, which make problem for app detection. If your is triggering everytime, then it is not a problem (from the compatibility point of view).