Android Messenger - 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 Messenger class.

This code example shows how to use the following methods:send
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
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:
    @Override 
    public void onCreate() { 
        super.onCreate(); 
        mAsyncServiceInfo = createHandler();
        mHandler = mAsyncServiceInfo.mHandler;
        mMessenger = new Messenger(mHandler);
    } 
 
    /** 
     * Sends the CMD_ASYNC_SERVICE_ON_START_INTENT message. 
     */ 
    @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;
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:send
            this.sb = new WeakReference<ServiceBinder>(sb);
        } 
 
        public void onServiceConnected(ComponentName className, IBinder service) {
	        //service has been connected to this, send the given message 
	        serviceMessenger = new Messenger(service);
	        sendToService(this.sb.get().in);
	    } 
	     
	    public void onServiceDisconnected(ComponentName className) {
	        //error during connection / something went wrong during binding. 
            //notify lock, since we have not set response to something, the main thread 
            //will recognize that something has gone wrong 
            this.sb.get().lock.notifyAll();
	    } 
 
        @Override 
        public void handleMessage(Message msg){
            this.sb.get().response = Message.obtain(msg);
             

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:send
 
        final Message m = Message.obtain();
        m.obj = result;
        m.what = resultCode;
        try { 
            messenger.send(m);
        } catch (RemoteException e) {
            // Couldn't report back, but there is nothing we can do to fix it 
        } 
    } 
 
    public void onClickCancel(final View v) {
        reportBackToCaller(CODE_CANCEL, null);
        finish();
    } 
 
    public void onClickConfirm(final View v) {
        final Bundle parameters = new Bundle();
        final int resultCode = mContents.apply(this, parameters);
        reportBackToCaller(resultCode, parameters);
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:
    @Override 
    public void onCreate() { 
        super.onCreate(); 
        mAsyncServiceInfo = createHandler();
        mHandler = mAsyncServiceInfo.mHandler;
        mMessenger = new Messenger(mHandler);
    } 
 
    /** 
     * Sends the CMD_ASYNC_SERVICE_ON_START_INTENT message. 
     */ 
    @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;
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:send
      msg.arg1=Activity.RESULT_CANCELED;
      msg.obj=e;
    } 
     
    try { 
      messenger.send(msg);
    } 
    catch (Exception e) {
      Log.w("LunchList", "Exception sending results to activity", e);
    } 
  } 
} 
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:
                                                                // of all 
                                                                // current 
                                                                // registered 
                                                                // clients. 
    int mValue = 0; // Holds last value set by a client.
    final Messenger mMessenger = new Messenger(new IncomingHandler()); // Target
                                                                       // we 
                                                                       // publish 
                                                                       // for 
                                                                       // clients 
                                                                       // to 
                                                                       // send 
                                                                       // messages 
                                                                       // to 
                                                                       // IncomingHandler. 
 
    // private final ServiceStub mBinder = new ServiceStub(this); 
 
    Context mContext;
 
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:getBinder
		// Get messager from the Activity 
		if (extras != null) {
			outMessenger = (Messenger) extras.get("MESSENGER");
		} 
		// Return our messenger to the Activity to get commands 
		return inMessenger.getBinder();
	} 
} 
6
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 void onClick(View view) {
		Intent intent = new Intent(this, DownloadService.class);
		// Create a new Messenger for the communication back 
		Messenger messenger = new Messenger(handler);
		intent.putExtra("MESSENGER", messenger);
		intent.setData(Uri.parse("http://www.vogella.de/index.html"));
		intent.putExtra("urlpath", "http://www.vogella.de/index.html");
		startService(intent);
	} 
 
	public void showToast(View view) {
		Toast.makeText(this, "Still interactive", Toast.LENGTH_SHORT).show();
	} 
} 
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:getBinder
     * When binding to the service, we return an interface to our messenger 
     * for sending messages to the service. 
     */ 
    @Override 
    public IBinder onBind(Intent intent) {
        return mMessenger.getBinder();
    } 
 
    /** 
     * Show a notification while this service is running. 
     */ 
    private void showNotification() { 
        // In this sample, we'll use the same text for the ticker and the expanded notification 
        CharSequence text = getText(R.string.remote_service_started);
 
        // Set the icon, scrolling text and timestamp 
        Notification notification = new Notification(R.drawable.stat_sample, text,
                System.currentTimeMillis());
 
        // The PendingIntent to launch our activity if the user selects this notification 
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java

Related Android Messenger Questions & Answers:

See Code Examples for Android Messenger Methods: