How can I create a scheduled action

Hello, I would like to maintain, for example, a sound or a function on the phone only for a certain time set by the user in the application. How could I do this?

Thanks