Handler obtainMessage - 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 obtainMessage method.

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. 
     */ 
8
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:obtainMessage, removeMessages, sendMessage
 
        absListView.invalidate();
    } 
 
    private void postUpdateItems() { 
        Message msg = mHandler.obtainMessage(MESSAGE_UPDATE_ITEMS,
                                             ItemManager.this);
 
        mHandler.removeMessages(MESSAGE_UPDATE_ITEMS);
        mPendingItemsUpdate = true;
 
        mHandler.sendMessage(msg);
    } 
 
    void setItemManaged(ItemManaged itemManaged) {
        mManaged = itemManaged;
 
        if (mManaged != null) {
            AbsListView absListView = mManaged.getAbsListView();
 
8
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:obtainMessage, sendMessage
		@Override 
		public void onReceive(Context context, Intent intent) {
			int intExtra = intent.getIntExtra("tab", 0);
			Log.i(TabChangeReceiver.class.getSimpleName(), "Recieved broadcast with extra=[" + intExtra + "]");
			 
			mHandler.sendMessage(mHandler.obtainMessage(SWITCH_TAB, intExtra, 0));
		} 
	} 
	 
	private TabHost host;
	public static final int SWITCH_TAB = 2545;
	protected static TabChangeReceiver receiver;
	 
} 
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:obtainMessage, removeMessages, sendMessage, sendMessageDelayed
 
        String url = ( String ) msg.obj;
        if ( msg.what == GET_REMOTE_IMAGE )
        { 
            // while decoding the new image, show the default album art 
            Message numsg = mParentHandler
                    .obtainMessage( REMOTE_IMAGE_DECODED, null );
            mParentHandler.removeMessages( REMOTE_IMAGE_DECODED );
            mParentHandler.sendMessageDelayed( numsg, 300 );
            Bitmap bm = getArtwork( url );
            if ( bm != null )
            { 
                numsg = mParentHandler.obtainMessage( REMOTE_IMAGE_DECODED, bm );
                mParentHandler.removeMessages( REMOTE_IMAGE_DECODED );
                mParentHandler.sendMessage( numsg );
            } 
        } 
    } 
     
    private Bitmap getArtwork( String urlstr )
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:obtainMessage, sendMessage
            executeMessage(msg);
            msg.recycle();
            return; 
        } 
         
        mH.sendMessage(msg);
    } 
     
    void executeMessage(Message msg) {
        switch (msg.what) {
            case DO_GET_TEXT_AFTER_CURSOR: {
                SomeArgs args = (SomeArgs)msg.obj;
                try { 
                    InputConnection ic = mInputConnection.get();
                    if (ic == null || !isActive()) {
                        Log.w(TAG, "getTextAfterCursor on inactive InputConnection");
                        args.callback.setTextAfterCursor(null, args.seq);
                        return; 
                    } 
                    args.callback.setTextAfterCursor(ic.getTextAfterCursor(

7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:obtainMessage, sendMessage
    public class TabChangeReceiver extends android.content.BroadcastReceiver{
		@Override 
		public void onReceive(Context context, Intent intent) {
			int intExtra = intent.getIntExtra("tab", 0);
			Log.i(TabChangeReceiver.class.getSimpleName(), "Recieved broadcast with extra=[" + intExtra + "]");
			mHandler.sendMessage(mHandler.obtainMessage(SWITCH_TAB, intExtra, 0));
		} 
	} 
 
	private OnClickListener goToTab1() {
		return new View.OnClickListener() {
			public void onClick(View v) {
				Intent intent = new Intent("com.novoda.TAB");
				intent.putExtra("tab", 0);
				sendBroadcast(intent);
			} 
		}; 
	}	 
	 
	private OnClickListener goToTab2() {
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:obtainMessage, removeMessages, sendMessage
	public static synchronized void sendBTCMotorMessage(int delay, int motor, int speed, int angle) {
		Bundle myBundle = new Bundle();
		myBundle.putInt("motor", motor);
		myBundle.putInt("speed", speed);
		myBundle.putInt("angle", angle);
		Message myMessage = btcHandler.obtainMessage();
		myMessage.setData(myBundle);
		myMessage.what = motor;
 
		if (delay == 0) {
 
			btcHandler.removeMessages(motor);
			btcHandler.sendMessage(myMessage);
 
		} else { 
			//btcHandler.removeMessages(motor); 
			btcHandler.sendMessageDelayed(myMessage, delay);
 
		} 
	} 
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:obtainMessage, removeMessages, sendMessageDelayed
    /** 
     * Start up the pulse to fade the screen, clearing any existing pulse to 
     * ensure that we don't have multiple pulses running at a time. 
     */ 
    void startFading() { 
        mHandler.removeMessages(MSG_FADE);
        scheduleFade(); 
    } 
 
    /** 
     * Stop the pulse to fade the screen. 
     */ 
    void stopFading() { 
        mHandler.removeMessages(MSG_FADE);
    } 
 
    /** 
     * Schedule a fade message for later. 
     */ 
    void scheduleFade() { 

7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:obtainMessage, sendMessageDelayed
    } 
 
    public void onStart() { 
        super.onStart(); 
        setEnabled(false); 
        mHandler.sendMessageDelayed(mHandler.obtainMessage(0), 1000);
    } 
 
    public boolean dispatchKeyEvent(KeyEvent event) {
        if (mConsuming) {
            //Slog.i(TAG, "Consuming: " + event); 
            return true; 
        } 
        //Slog.i(TAG, "Dispatching: " + event); 
        return super.dispatchKeyEvent(event);
    } 
 
    private void setEnabled(boolean enabled) {
        Button b = (Button)findViewById(R.id.button1);
        if (b != null) {
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:obtainMessage, sendMessageDelayed
    this.autoFocusMessage = autoFocusMessage;
  } 
 
  public void onAutoFocus(boolean success, Camera camera) {
    if (autoFocusHandler != null) {
      Message message = autoFocusHandler.obtainMessage(autoFocusMessage, success);
      // Simulate continuous autofocus by sending a focus request every 
      // AUTOFOCUS_INTERVAL_MS milliseconds. 
      //Log.d(TAG, "Got auto-focus callback; requesting another"); 
      autoFocusHandler.sendMessageDelayed(message, AUTOFOCUS_INTERVAL_MS);
      autoFocusHandler = null;
    } else { 
      Log.d(TAG, "Got auto-focus callback, but no handler for it");
    } 
  } 
 
} 
7
CodeRank
Experience pair programming with AI  Get Codota for Java

Related Handler obtainMessage Questions & Answers:

obtainMessage Method Overview
Same as obtainMessage(), except that it also sets the what, arg1 and arg2 members of the returned Message.
See Code Examples for other Android Handler Methods: