How to set a timer in android

前端 未结 13 1881
天命终不由人
天命终不由人 2020-11-22 06:43

What is the proper way to set a timer in android in order to kick off a task (a function that I create which does not change the UI)? Use this the Java way: http://docs.ora

13条回答
  •  眼角桃花
    2020-11-22 07:20

    It is situational.

    The Android documentation suggests that you should use AlarmManager to register an Intent that will fire at the specified time if your application may not be running.

    Otherwise, you should use Handler.

    Note: The Alarm Manager is intended for cases where you want to have your application code run at a specific time, even if your application is not currently running. For normal timing operations (ticks, timeouts, etc) it is easier and much more efficient to use Handler.

提交回复
热议问题