Android Handler - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android Handler class.

This code example shows how to use the following methods:
        } 
    } 
 
    UpdateLockService(Context context) {
        mContext = context;
        mLocks = new LockWatcher(new Handler(), "UpdateLocks");
 
        // Consider just-booting to be a reasonable time to allow 
        // interruptions for update installation etc. 
        sendLockChangedBroadcast(true); 
    } 
 
    void sendLockChangedBroadcast(boolean state) {
        // Safe early during boot because this broadcast only goes to registered receivers. 
        long oldIdent = Binder.clearCallingIdentity();
        try { 
            Intent intent = new Intent(UpdateLock.UPDATE_LOCK_CHANGED)
                    .putExtra(UpdateLock.NOW_IS_CONVENIENT, state)
                    .putExtra(UpdateLock.TIMESTAMP, System.currentTimeMillis())
                    .addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT); 
Full Snippet Info
8
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:
		return sManagerThread;
	} 
	 
	public void run() { 
		Looper.prepare();
		mHandler = new Handler();
		mInfoManager.setHandler(mHandler);
		mControlManager.setHandler(mHandler);
		mMusicManager.setHandler(mHandler);
		mVideoManager.setHandler(mHandler);
		mTvShowManager.setHandler(mHandler);
		Looper.loop();
	} 
	 
	public static InfoManager info(INotifiableController controller) {
		final InfoManager im = get().mInfoManager;
		im.setController(controller);
		return im;
	} 
	public static ControlManager control(INotifiableController controller) {
Full Snippet Info
8
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods: post
    final Handler handler = new Handler();
    Timer t = new Timer();
    t.schedule(new TimerTask() {
      @Override 
      public void run() { 
        handler.post(new Runnable() {
          public void run() { 
            // This will kill the parent, a bad idea. 
//            parent.finish(); 
            // This will start the browser, a better idea 
            launchIntent(new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com/")));
          } 
        }); 
      } 
    }, DELAY_MS);
  } 
} 
Full Snippet Info
9
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:
 * Schedulers that have Android specific functionality 
 */ 
public class AndroidSchedulers { 
 
    private static final Scheduler MAIN_THREAD_SCHEDULER =
            new HandlerThreadScheduler(new Handler(Looper.getMainLooper()));
 
    private AndroidSchedulers(){ 
 
    } 
 
    /** 
     * {@link Scheduler} which uses the provided {@link Handler} to execute an action 
     * @param handler The handler that will be used when executing the action 
     * @return A handler based scheduler 
     */ 
    public static Scheduler handlerThread(final Handler handler) {
        return new HandlerThreadScheduler(handler);
    } 
 
Full Snippet Info
8
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods: postDelayed, removeCallbacks
builder.setCheckedItem(clickedPos);
    } 
 
    private void playRingtone(int position, int delayMs) {
        handler.removeCallbacks(this);
        sampleRingtonePos = position;
        handler.postDelayed(this, delayMs);
    } 
 
    @Override 
    public void run() { 
        if (sampleRingtonePos == silentPos) {
            ringtoneManager.stopPreviousRingtone();
            return; 
        } 
        if (defaultRingtone != null && defaultRingtone.isPlaying()) {
            defaultRingtone.stop();
            defaultRingtone = null;
        } 
Full Snippet Info
10
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods: obtainMessage, sendMessage
     */ 
    @Override 
    public int onStartCommand(Intent intent, int flags, int startId) {
        if (DBG) Slog.d(TAG, "onStartCommand");
 
        Message msg = mHandler.obtainMessage();
        msg.what = CMD_ASYNC_SERVICE_ON_START_INTENT;
        msg.arg1 = flags;
        msg.arg2 = startId;
        msg.obj = intent;
        mHandler.sendMessage(msg);
 
        return mAsyncServiceInfo.mRestartFlags;
    } 
 
    /** 
     * Called when service is destroyed. After returning the 
     * service is dead and no more processing should be expected 
     * to occur. 
     */ 
Full Snippet Info
8
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods: hasMessages
@RunWith(TestRunners.WithDefaults.class) 
public class MessengerTest { 
 
    @Test 
    public void testMessengerSend() throws Exception { 
        Handler handler = new Handler();
        Messenger messenger = new Messenger(handler);
 
        ShadowLooper.pauseMainLooper(); 
        Message msg = Message.obtain(null, 123);
        messenger.send(msg);
 
        assertTrue(handler.hasMessages(123));
        ShadowHandler.runMainLooperOneTask(); 
        assertFalse(handler.hasMessages(123));
    } 
} 
Full Snippet Info
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:
public class PlatLogoActivity extends Activity {
    Toast mToast;
    ImageView mContent;
    Vibrator mZzz = new Vibrator();
    int mCount;
    final Handler mHandler = new Handler();
 
    Runnable mSuperLongPress = new Runnable() {
        public void run() { 
            mCount++; 
            mZzz.vibrate(50 * mCount); 
            final float scale = 1f + 0.25f * mCount * mCount; 
            mContent.setScaleX(scale); 
            mContent.setScaleY(scale); 
 
            if (mCount <= 3) { 
                mHandler.postDelayed(mSuperLongPress, ViewConfiguration.getLongPressTimeout()); 
            } else { 
                try { 
                    startActivity(new Intent(Intent.ACTION_MAIN) 
Full Snippet Info
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods: post
        if (DEBUG) Slog.d(TAG, String.format( "Startup with UMS connection %s (media state %s)",
                mUmsAvailable, Environment.getExternalStorageState()));
         
        HandlerThread thr = new HandlerThread("SystemUI StorageNotification");
        thr.start();
        mAsyncEventHandler = new Handler(thr.getLooper());
 
        onUsbMassStorageConnectionChanged(connected);
    } 
 
    /* 
     * @override com.android.os.storage.StorageEventListener 
     */ 
    @Override 
    public void onUsbMassStorageConnectionChanged(final boolean connected) {
        mAsyncEventHandler.post(new Runnable() {
            @Override 
            public void run() { 
                onUsbMassStorageConnectionChangedAsync(connected);
            } 
        }); 
Full Snippet Info
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods: removeMessages, sendEmptyMessageDelayed
			handled = super.onTouchEvent(ev);
		} 
		return handled;
	} 
 
	@Override 
	protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
	{ 
		super.onMeasure(widthMeasureSpec, heightMeasureSpec);
 
		int maxWidth = 0;
		int maxHeight = 0;
 
//		if (DBG) { 
//			int w = MeasureSpec.getSize(widthMeasureSpec); 
//			int wm = MeasureSpec.getMode(widthMeasureSpec); 
//			int h = MeasureSpec.getSize(heightMeasureSpec); 
//			int hm = MeasureSpec.getMode(heightMeasureSpec); 
// 
//			Log.i(LCAT, "w: " + w + " wm: " + wm + " h: " + h + " hm: " + hm); 
Full Snippet Info
8
CodeRank
Connect your IDE to all the code out there  Get Codota for Java

Related Android Handler Questions & Answers:

Other Android Handler Examples

15:			setContentView(R.layout.activity_splash);
16:	
17:			new Handler().postDelayed(new Runnable() {
18:	
19:				/*

Read More

34:		// Handler to update UI timer, progress bar etc,.
35:		private Handler mHandler = new Handler();;
36:		private SongsManager songManager;
37:		private Utilities utils;
38:		private int seekForwardTime = 5000; // 5000 milliseconds
-
34:		// Handler to update UI timer, progress bar etc,.
35:		private Handler mHandler = new Handler();;
36:		private SongsManager songManager;
37:		private Utilities utils;
38:		private int seekForwardTime = 5000; // 5000 milliseconds

Read More

See Code Examples for Android Handler Methods: