scheduling alarm for every second in android 5.1

后端 未结 7 2230
醉梦人生
醉梦人生 2020-12-05 20:04


I want to run alarm service for every second in my application.It is working fine below 5.1 version. but it is not triggering in 5.1 devices. I am using commonsware wa

7条回答
  •  时光说笑
    2020-12-05 20:29

    Why would you do that?
    Use an handler instead:

    Runnable runnable = new Runnable() {
        @Override
        public void run() {
            // do your stuff here, called every second
            mHandler.postDelayed(this, 1000);
        }
    };
    
    // start it with:
    mHandler.post(runnable);
    

    And use the following to stop your 1 sec timer:

    mHandler.removeCallbacks(runnable);
    

提交回复
热议问题