zoukankan      html  css  js  c++  java
  • AsyncHandler

    package com.ango.deskclock;
    
    import android.content.Context;
    import android.content.Intent;
    import android.os.Handler;
    import android.os.HandlerThread;
    
    /**
     * Helper class for managing the background thread used to perform io operations
     * and handle async broadcasts.
     */
    final class AsyncHandler {
    
        private static final HandlerThread sHandlerThread =
                new HandlerThread("AsyncHandler");
        private static final Handler sHandler;
        private static Runnable aRunnable;
    
        static {
            sHandlerThread.start();
            sHandler = new Handler(sHandlerThread.getLooper());
        }
    
        public static void post(Runnable r) {
            sHandler.post(r);
        }
        
        public static final boolean postDelayed(Context context, Alarm alarm, long delayMillis) {
        	final Context sContext = context;
        	final Alarm sAlarm = alarm;
        	aRunnable = new Runnable() {
                @Override public void run() {
                    Intent playAlarm = new Intent(Alarms.ALARM_ALERT_ACTION);
                    playAlarm.putExtra(Alarms.ALARM_INTENT_EXTRA, sAlarm);
                    sContext.startService(playAlarm);
                  }
        	};
        	return sHandler.postDelayed(aRunnable, delayMillis);
        }
        
        public static final void removeCallbacks (){
        	sHandler.removeCallbacks(aRunnable);
        }
    
        private AsyncHandler() {}
    }

            AsyncHandler.post(new Runnable() {
                @Override public void run() {
                    handleIntent(context, intent);
                    result.finish();
                    wl.release();
                }
            });
    


    //        // Play the alarm alert and vibrate the device after 10 seconds so that the user can dismiss or snooze before the alarm alert.
    //        Intent playAlarm = new Intent(Alarms.ALARM_ALERT_ACTION);
    //        playAlarm.putExtra(Alarms.ALARM_INTENT_EXTRA, alarm);
    //        context.startService(playAlarm);
            AsyncHandler.postDelayed(context, alarm, 10000); 
    

            AsyncHandler.removeCallbacks();  // remove the AsyncHandler.postDelayed(context, alarm, 10000) in AlarmReceiver.java
    






    版权声明:本文博客原创文章,博客,未经同意,不得转载。

  • 相关阅读:
    JavaScript运行机制 Event Loop
    async 函数
    JavaScript Promise 对象
    pc端rest.css
    微信小程序公用样式类
    移动端base.css
    RegExp正则对象匹配规则
    RegExp正则相关方法
    mysql(五)事务
    mysql(四)海量数据优化
  • 原文地址:https://www.cnblogs.com/yxwkf/p/4754439.html
Copyright © 2011-2022 走看看