App starting triggerd both start and end, why?

Post your questions and help other users.

Moderator: Martin

Post Reply
User avatar
jassing
Posts: 94
Joined: 16 Jul 2017 01:42
Location: SF Bay Area

App starting triggerd both start and end, why?

Post by jassing » 05 Dec 2019 04:05

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.
Attachments
app_start_end_issue.xml
(1.42 KiB) Downloaded 614 times

User avatar
Desmanto
Posts: 2709
Joined: 21 Jul 2017 17:50

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

Post by Desmanto » 05 Dec 2019 04:20

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.
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.

User avatar
jassing
Posts: 94
Joined: 16 Jul 2017 01:42
Location: SF Bay Area

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

Post by jassing » 05 Dec 2019 05:39

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

User avatar
Desmanto
Posts: 2709
Joined: 21 Jul 2017 17:50

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

Post by Desmanto » 05 Dec 2019 10:37

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
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.

User avatar
jassing
Posts: 94
Joined: 16 Jul 2017 01:42
Location: SF Bay Area

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

Post by jassing » 05 Dec 2019 17:06

Thanks. So, is there a way to tell if an app was really started?

User avatar
Desmanto
Posts: 2709
Joined: 21 Jul 2017 17:50

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

Post by Desmanto » 06 Dec 2019 10:48

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.
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.

User avatar
jassing
Posts: 94
Joined: 16 Jul 2017 01:42
Location: SF Bay Area

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

Post by jassing » 07 Dec 2019 01:05

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.

User avatar
Desmanto
Posts: 2709
Joined: 21 Jul 2017 17:50

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

Post by Desmanto » 07 Dec 2019 02:36

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).
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.

Post Reply