标签:des android java os io for art ar
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
标签:des android java os io for art ar
原文地址:http://blog.csdn.net/llrraa2010/article/details/38456921