How to execute a flow and wait til it finishes

Post your questions and help other users.

Moderator: Martin

Post Reply
User avatar
aximili
Posts: 23
Joined: 28 Jun 2018 11:14

How to execute a flow and wait til it finishes

Post by aximili » 15 Jul 2018 07:01

I created a flow to check for movement.
(by getting device orientation several times. If the x,y,z stays very similar after several seconds, set global_moving = false, otherwise true as soon as a difference is found)

I have another flow that executes that flow, then check for the value of global_moving.
The problem is it moves to the next action (ie. reading global_moving) before the check-for-movement flow even finishes.
How can I make it wait til it finishes before checking the value? (I tried Flow Execution Policy but it didn't make any difference)

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

Re: How to execute a flow and wait til it finishes

Post by Desmanto » 15 Jul 2018 10:29

Waiting for flow before continuing.
At another flow, use condition Flow Executing, choose that flow which check movement. True, go to sleep, example 200 ms, and loop back to the flow executing. False continue to the main branch of the flow. Essentially it check if the flow is still running, wait for 200 ms infinitely before rechecking again. Once it sense the flow has stopped, then it will execute the main logic of the flow.

Better solution
But you have actually use the incorrect trigger. Use device orientation will drain your battery a bit faster. A better solution is to use the API which has been provided by google since 2014. Automagic has it already for a long time, but almost never discussed here. Use Trigger User Activity (Experimental). This use Google API, which has been trained by machine learning to detect body movement. I am actually scared, that sometimes it can be so accurate. :shock:

Because you want to detect stillness, use Activity detected : Still - begin. If you want to trigger when you are on movement (stillness end), use Activity detected : Still - End. You can define the confidence level, which range from 0-100. 100 is absolutely sure, while lower than that is determined on how many other possible activities detected by the API.
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
aximili
Posts: 23
Joined: 28 Jun 2018 11:14

Re: How to execute a flow and wait til it finishes

Post by aximili » 16 Jul 2018 10:04

I see that's awesome (although scary yes lol)
Thanks a lot Desmanto for the thorough reply!

Post Reply