Handler hasMessages - top ranked examples from Open Source projects

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

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));
    } 
} 
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:hasMessages, removeMessages, sendEmptyMessage
 
        // Show notification when we start the timer 
        showNotification(); 
 
        mStart = System.currentTimeMillis();
        mHandler.removeMessages(0);
        mHandler.sendEmptyMessage(0);
         
        // Keep restarting until we stop the service 
        return START_STICKY;
    } 
 
    @Override 
    public void onDestroy() { 
        Log.i(TAG, "onDestroy");
        // Cancel the ongoing notification. 
        mNM.cancel(TIMER_NOTIFICATION);
         
        mHandler.removeMessages(0);
    } 

6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:hasMessages, removeMessages
        b.setText(label);
    } 
 
 
    public void insertItems(View v) {
        if (mInsertHandler.hasMessages(0)) {
            mInsertHandler.removeMessages(0);
            setInsertButtonText(); 
        } else { 
            mInsertHandler.sendEmptyMessage(0);
        } 
    } 
 
    Handler mInsertHandler = new Handler() {
        @Override 
        public void handleMessage(Message msg) { 
 
            if (mNumToInsert-- > 0) { 
                addAlbum(); 
                runOnUiThread(mDisplayUpdater); 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:hasMessages, obtainMessage, sendMessageDelayed
            // interface to clear the audio pipeline. 
            delay = 1000;
        } else { 
            // Insert the same delay for headset connection so that the connection event is not 
            // broadcast before the disconnection event in case of fast removal/insertion 
            if (mHandler.hasMessages(0)) {
                delay = 1000;
            } 
        } 
        mWakeLock.acquire();
        mHandler.sendMessageDelayed(mHandler.obtainMessage(0,
                                                           mHeadsetState,
                                                           mPrevHeadsetState,
                                                           mHeadsetName),
                                    delay);
    } 
 
    private synchronized final void sendIntents(int headsetState, int prevHeadsetState, String headsetName) {
        int allHeadsets = SUPPORTED_HEADSETS;
        for (int curHeadset = 1; allHeadsets != 0; curHeadset <<= 1) {
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:hasMessages, obtainMessage
     * <p/> 
     * Binding late is preferred as any custom preference types created in 
     * {@link #onCreate(Bundle)} are able to have their views recycled. 
     */ 
    private void postBindPreferences() { 
        if (mHandler.hasMessages(MSG_BIND_PREFERENCES)) return;
        mHandler.obtainMessage(MSG_BIND_PREFERENCES).sendToTarget();
    } 
 
    private void bindPreferences() { 
        final PreferenceScreen preferenceScreen = getPreferenceScreen();
        if (preferenceScreen != null) {
            preferenceScreen.bind(lv);
        } 
    } 
 
    /** 
     * Creates the {@link PreferenceManager}. 
     * 
     * @return The {@link PreferenceManager} used by this activity. 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:hasMessages, obtainMessage
     * <p> 
     * Binding late is preferred as any custom preference types created in 
     * {@link #onCreate(Bundle)} are able to have their views recycled. 
     */ 
    private void postBindPreferences() { 
        if (mHandler.hasMessages(MSG_BIND_PREFERENCES)) return;
        mHandler.obtainMessage(MSG_BIND_PREFERENCES).sendToTarget();
    } 
     
    private void bindPreferences() { 
        final PreferenceScreen preferenceScreen = getPreferenceScreen();
        if (preferenceScreen != null) {
        	try { 
        		if (lv == null) lv = getListView();
        		preferenceScreen.bind(lv);
        	} catch (Exception e) {        		
        	} 
        } 
    } 
     
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:hasMessages, obtain
		return true; 
	} 
 
	void show(CharSequence text, int style, int duration) {
		MessageHolder holder = new MessageHolder(text, style, duration);
		if ((mHandler.hasMessages(MESSAGE_HIDE))) {
			mMessageHolderQueue.add(holder);
		} 
		else { 
			Message.obtain(mHandler, MESSAGE_SHOW, holder).sendToTarget();
		} 
    } 
 
	static class MessageHolder implements Parcelable {
 
		CharSequence text;
		int style;
		int duration;
 
		public MessageHolder(CharSequence text, int style, int duration) {
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:hasMessages, sendEmptyMessage
    public void reloadPreference() { 
        if (mPopup != null) mPopup.reloadPreference();
    } 
 
    protected void dismissPopupDelayed() { 
        if (!mHandler.hasMessages(MSG_DISMISS_POPUP)) {
            mHandler.sendEmptyMessage(MSG_DISMISS_POPUP);
        } 
    } 
 
    private class MainHandler extends Handler {
        @Override 
        public void handleMessage(Message msg) {
            switch (msg.what) {
                case MSG_DISMISS_POPUP:
                    dismissPopup(); 
                    break; 
            } 
        } 
    } 
5
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:hasMessages
         
        mH.sendMessage(msg);
    } 
     
    public boolean hasMessages(int what) {
        return mH.hasMessages(what);
    } 
     
    public void removeMessages(int what) {
        mH.removeMessages(what);
    } 
     
    public void removeMessages(int what, Object obj) {
        mH.removeMessages(what, obj);
    } 
     
    public void sendMessage(Message msg) {
        mH.sendMessage(msg);
    } 
     
5
CodeRank
Experience pair programming with AI  Get Codota for Java

Related Handler hasMessages Questions & Answers:

hasMessages Method Overview
Check if there are any pending posts of messages with code 'what' and whose obj is 'object' in the message queue.
See Code Examples for other Android Handler Methods: