Skip to content
Advertisement

Add delay to a loop in android without stalling the UI Thread

I have been looking all over the Android Studio Docs and StackOverflow, but I can not seem to find a way to do the equivalent of what is done in IOS here: Adding Delay In A For Loop Without Blocking UI in Android.

I have tried to use a Handler, but instead of running the code like:

JavaScript

The code seems to be run as follows:

JavaScript

The code I am using is stuctured like this:

JavaScript

The behavior I see when running this Activity is that is skips it, and after 500ms it goes to the next Activity (with expected result) but without showing the user what’s happening.

How would I delay the loop so the user can see what’s happening?


To clarivy:

The current state (after moveCard()) needs to be shown for x ms before going though the logic of my while loop again.

This is done untill the final state is has been reached.

Then the next Activity is started.


JavaScript

Advertisement

Answer

Maybe Creating Something like this should work,

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement