/** * Sends this message using one three methods: * * <ul> * <li>If the current thread is the same thread as the message Handler's thread, it is * dispatched immediately to the Handler * <li>If this TiMessenger is currently blocking, it is pushed into the internal message queue * to be processed by the next call to {@link #dispatchMessage()} * <li>If this TiMessenger is <b>NOT</b> current blocking, it is queued to it's Handler normally * by using msg.sendToTarget() * </ul> * * @param message The message to send */ public void sendMessage(Message message) { Handler target = message.getTarget(); long currentThreadId = Thread.currentThread().getId(); long targetThreadId = -1; if (target != null) { targetThreadId = target.getLooper().getThread().getId(); } if (target != null && currentThreadId == targetThreadId) { target.dispatchMessage(message); } else { if (isBlocking()) { try { messageQueue.put(message); } catch (InterruptedException e) { Log.w(TAG, "Interrupted trying to put new message, sending to handler", e); message.sendToTarget(); } } else { message.sendToTarget(); } } }
protected boolean onTap(int index) { // System.out.println("item onTap: "+index); Bitmap[] bmps = new Bitmap[3]; if (index % 2 == 0) { try { bmps[0] = BitmapFactory.decodeStream(mContext.getAssets().open("marker1.png")); bmps[1] = BitmapFactory.decodeStream(mContext.getAssets().open("marker2.png")); bmps[2] = BitmapFactory.decodeStream(mContext.getAssets().open("marker3.png")); } catch (IOException e) { e.printStackTrace(); } } else { try { bmps[2] = BitmapFactory.decodeStream(mContext.getAssets().open("marker1.png")); bmps[1] = BitmapFactory.decodeStream(mContext.getAssets().open("marker2.png")); bmps[0] = BitmapFactory.decodeStream(mContext.getAssets().open("marker3.png")); } catch (IOException e) { e.printStackTrace(); } } // pop.showPopup(bmps, getItem(index).getPoint(), 32); // if (null == mToast) // mToast = Toast.makeText(mContext, getItem(index).getTitle(), Toast.LENGTH_SHORT); // else mToast.setText(getItem(index).getTitle()); // mToast.show(); if (mH != null) { mH.dispatchMessage(mH.obtainMessage(LocationOverlayDemo.MSG_HANDLE_ITEM_TOUCH + index)); } return true; }
@Override protected void onPostExecute(BluetoothSocket result) { super.onPostExecute(result); closeDialog(); message.obj = result; handler.dispatchMessage(message); }
@Override public void run() { try { while (!Thread.currentThread().isInterrupted()) { Message msg = read(); if (msg != null) { mainHandler.dispatchMessage(mainHandler.obtainMessage(MSG_INPUT, msg)); } else { mainHandler.dispatchMessage(mainHandler.obtainMessage(MSG_TEARDOWN, "null message")); } } } catch (IOException e) { mainHandler.dispatchMessage(mainHandler.obtainMessage(MSG_INPUT_ERROR, e)); } try { is.close(); } catch (IOException ignored) { } }
@Override public void dispatchMessage(Message msg) { // TODO Auto-generated method stub super.dispatchMessage(msg); }
public final void send(Message message) { message.arg2 = Binder.getCallingUid(); handler.dispatchMessage(message); }
public void a(Message message) throws RemoteException { message.arg2 = Binder.getCallingUid(); a.dispatchMessage(message); }
private void sendMessage(Request request, Object obj) { Message msg = handler.obtainMessage(request.ordinal()); msg.obj = obj; handler.dispatchMessage(msg); }