androidmultithreadingactionandroid-task

How to delay some action in Android so that a task completes after a set Delay?


I am trying to develop an app in Android which has a few actions that need to be executed after a set period of time.

Anything which I can do to fulfil this?


Solution

  • If you're using java to code in android Studio then I suggest you to use the Handler, that will execute your action after a determined span of time

    In your activity's onCreate method do this:

     int any_delay_in_ms = 1000; //1Second interval
        new Handler().postDelayed(() -> {
            //TODO Perform your action here
        }, any_delay_in_ms);