Example usage for android.os Message obtain

List of usage examples for android.os Message obtain

Introduction

In this page you can find the example usage for android.os Message obtain.

Prototype

public static Message obtain() 

Source Link

Document

Return a new Message instance from the global pool.

Usage

From source file:com.adjust.sdk.ActivityHandler.java

private void timerFired() {
    Message message = Message.obtain();
    message.arg1 = SessionHandler.TIMER_FIRED;
    sessionHandler.sendMessage(message);
}

From source file:org.sufficientlysecure.keychain.ui.dialog.AddEditSmartPGPAuthorityDialogFragment.java

/**
 * Send message back to handler which is initialized in a activity
 *
 *///from w  w  w .jav a 2s.co  m
private void sendMessageToHandler(Bundle data) {
    Message msg = Message.obtain();
    if (data != null) {
        msg.setData(data);
    }

    try {
        mMessenger.send(msg);
    } catch (RemoteException e) {
        Log.w(Constants.TAG, "Exception sending message, Is handler present?", e);
    } catch (NullPointerException e) {
        Log.w(Constants.TAG, "Messenger is null!", e);
    }
}

From source file:de.qspool.clementineremote.ui.MainActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (event.getAction() == KeyEvent.ACTION_DOWN) {
        int currentVolume = App.mClementine.getVolume();
        // Control the volume of clementine if enabled in the options
        if (mSharedPref.getBoolean(App.SP_KEY_USE_VOLUMEKEYS, true)) {
            int volumeInc = Integer
                    .parseInt(mSharedPref.getString(App.SP_VOLUME_INC, Clementine.DefaultVolumeInc));
            switch (keyCode) {
            case KeyEvent.KEYCODE_VOLUME_DOWN:
                Message msgDown = Message.obtain();
                msgDown.obj = ClementineMessageFactory
                        .buildVolumeMessage(App.mClementine.getVolume() - volumeInc);
                App.mClementineConnection.mHandler.sendMessage(msgDown);
                if (currentVolume >= volumeInc) {
                    currentVolume -= volumeInc;
                } else {
                    currentVolume = 0;// w w w. j  a va  2 s .com
                }
                makeToast(getString(R.string.playler_volume) + " " + currentVolume + "%", Toast.LENGTH_SHORT);
                return true;
            case KeyEvent.KEYCODE_VOLUME_UP:
                Message msgUp = Message.obtain();
                msgUp.obj = ClementineMessageFactory
                        .buildVolumeMessage(App.mClementine.getVolume() + volumeInc);
                App.mClementineConnection.mHandler.sendMessage(msgUp);
                if ((currentVolume + volumeInc) >= 100) {
                    currentVolume = 100;
                } else {
                    currentVolume += volumeInc;
                }
                makeToast(getString(R.string.playler_volume) + " " + currentVolume + "%", Toast.LENGTH_SHORT);
                return true;
            default:
                break;
            }
        }
    }
    return super.onKeyDown(keyCode, event);
}

From source file:com.yangtsaosoftware.pebblemessenger.services.PebbleCenter.java

@Override
public void onCreate() {
    super.onCreate();
    Handler pebbleCenterHandler = new PebbleCenterHandler();
    mPebbleCenterHandler = new Messenger(pebbleCenterHandler);
    Constants.log(TAG_NAME, "Create PebbleCenter Messenger.");
    loadPref();/*from w  ww.jav  a2 s  .  co  m*/
    _contex = this;
    //   busyBegin=new Time();
    //        waitQueue=new ArrayDeque<PebbleMessage>();
    sendQueue = new ArrayDeque<PebbleDictionary>();
    bindService(new Intent(this, MessageProcessingService.class), connToMessageProcessing,
            Context.BIND_AUTO_CREATE);
    Thread prepareThread = new PrepareThread();
    prepareThread.start();
    Thread sendMsgThread = new SendMsgThread();
    sendMsgThread.start();
    isPebbleEnable = PebbleKit.isWatchConnected(_contex);
    PebbleKit.registerReceivedDataHandler(_contex, new PebbleKit.PebbleDataReceiver(Constants.PEBBLE_UUID) {
        @Override
        public void receiveData(Context context, int transactionId, PebbleDictionary data) {
            PebbleKit.sendAckToPebble(_contex, transactionId);
            //          appStatue++;
            Constants.log(TAG_NAME, "Received data form pebble");
            switch (data.getUnsignedIntegerAsLong(ID_COMMAND).intValue()) {
            case REQUEST_TRANSID_CALL_TABLE: {
                Constants.log(TAG_NAME, "Request call table.");
                clean_SendQue();
                Message msg = Message.obtain();
                msg.what = MessageProcessingService.MSG_GET_CALL_TABLE;
                try {
                    rMessageProcessingHandler.send(msg);
                } catch (RemoteException e) {
                    e.printStackTrace();
                }
            }
                break;
            case REQUEST_TRANSID_MESSAGE_TABLE: {
                Constants.log(TAG_NAME, "Request message table.");
                clean_SendQue();
                Message msg = Message.obtain();
                msg.what = MessageProcessingService.MSG_GET_MESSAGE_TABLE;
                try {
                    rMessageProcessingHandler.send(msg);
                } catch (RemoteException e) {
                    e.printStackTrace();
                }
            }
                break;
            case REQUEST_TRANSID_CALL: {
                clean_SendQue();
                Message msg = Message.obtain();
                msg.what = MessageProcessingService.MSG_GET_CALL;
                Bundle b = new Bundle();
                b.putString(MessageDbHandler.COL_CALL_ID, data.getString(ID_EXTRA_DATA));
                Constants.log(TAG_NAME, "Request call id:" + data.getString(ID_EXTRA_DATA));

                msg.setData(b);
                try {
                    rMessageProcessingHandler.send(msg);
                } catch (RemoteException e) {
                    e.printStackTrace();
                }

            }
                break;
            case REQUEST_TRANSID_MESSAGE:
                clean_SendQue();
                Message msg = Message.obtain();
                msg.what = MessageProcessingService.MSG_GET_MESSAGE;
                Bundle b = new Bundle();
                b.putString(MessageDbHandler.COL_MESSAGE_ID, data.getString(ID_EXTRA_DATA));
                Constants.log(TAG_NAME, "Request message id:" + data.getString(ID_EXTRA_DATA));

                msg.setData(b);
                try {
                    rMessageProcessingHandler.send(msg);
                } catch (RemoteException e) {
                    e.printStackTrace();
                }
                break;
            case REQUEST_TRANSID_PICKUP_PHONE:
                TelephonyManager telMag = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
                Constants.log("Receivephone", "Receive phone:" + data.getString(ID_EXTRA_DATA2));
                if (telMag.getCallState() == TelephonyManager.CALL_STATE_RINGING) {
                    switch (data.getUnsignedIntegerAsLong(ID_EXTRA_DATA).intValue()) {
                    case REQUEST_EXTRA_SPEAKER_ON:
                        answerCall(true);
                        break;
                    case REQUEST_EXTRA_SPEAKER_OFF:
                        answerCall(false);
                        break;
                    }
                } else {
                    switch (data.getUnsignedIntegerAsLong(ID_EXTRA_DATA).intValue()) {
                    case REQUEST_EXTRA_SPEAKER_ON:
                        dialNumber(data.getString(ID_EXTRA_DATA2), true);
                        break;
                    case REQUEST_EXTRA_SPEAKER_OFF:
                        dialNumber(data.getString(ID_EXTRA_DATA2), false);
                        break;
                    }

                }
                //                pebbleBusy = false;
                break;
            case REQUEST_TRANSID_HANGOFF_PHONE:
                endCall();
                //                pebbleBusy=false;

                break;
            case REQUEST_TRANSID_HANGOFF_SMS1:
                Constants.log(TAG_NAME, "Request hangoff and send sms1");

                endCall();
                doSendSMSTo(data.getString(ID_EXTRA_DATA), sms1);
                //               pebbleBusy=false;

                break;
            case REQUEST_TRANSID_HANGOFF_SMS2:
                Constants.log(TAG_NAME, "Request hangoff and send sms2");

                endCall();
                doSendSMSTo(data.getString(ID_EXTRA_DATA), sms2);
                //              pebbleBusy=false;

                break;
            case REQUEST_TRANSID_CLOSE_APP:
                Constants.log(TAG_NAME, "Request close app command.");
                sendMsgThreadHandler.sendEmptyMessage(SEND_CLOSE_APP);
                //               need_delay=true;

                break;
            case REQUEST_TRANSID_NEXTPAGE:
                Constants.log(TAG_NAME, "Request send next page.");

                sendMsgThreadHandler.sendEmptyMessage(SEND_NEXT_PAGE);
                break;
            case REQUEST_TRANSID_READ_NOTIFY: {
                Constants.log(TAG_NAME, "Request  read msg");
                Message read_msg = Message.obtain();
                read_msg.what = MessageProcessingService.MSG_READ;
                Bundle bd = new Bundle();
                bd.putString(MessageDbHandler.COL_MESSAGE_ID,
                        data.getUnsignedIntegerAsLong(ID_EXTRA_DATA).toString());
                read_msg.setData(bd);
                try {
                    rMessageProcessingHandler.send(read_msg);
                } catch (RemoteException e) {
                    e.printStackTrace();
                }
            }
                break;
            case REQUEST_TRANSID_IM_FREE:
                Constants.log(TAG_NAME, "Request pebble app is free to receive data.");

                //               need_delay = data.getUnsignedInteger(ID_EXTRA_DATA).intValue() == REQUEST_EXTRA_DELAY_ON ;
                //               clean_SendQue();
                break;
            case REQUEST_TRANSID_VERSION: {
                send_test_get_return = true;
                String result = data.getString(ID_EXTRA_DATA);
                Constants.log("PmpVersion", result);
                StringTokenizer tokens = new StringTokenizer(result, ".");

                Intent inner_intent = new Intent(SetupFragment.class.getName());
                inner_intent.putExtra(Constants.BROADCAST_VERSION,
                        new byte[] { Byte.parseByte(tokens.nextToken()), Byte.parseByte(tokens.nextToken()),
                                Byte.parseByte(tokens.nextToken()) });
                LocalBroadcastManager.getInstance(context).sendBroadcast(inner_intent);
                sendMsgThreadHandler.sendEmptyMessage(SEND_CLOSE_APP);
                break;
            }
            }
        }
    });

    PebbleKit.registerReceivedAckHandler(_contex, new PebbleKit.PebbleAckReceiver(Constants.PEBBLE_UUID) {
        @Override
        public void receiveAck(Context context, int transactionId) {
            Constants.log(TAG_NAME, "Get a receiveAck:" + String.valueOf(transactionId));
            switch (transactionId) {
            case TRANS_ID_COMMON:
                Constants.log(TAG_NAME, "Send continue...");
                //                  pebbleBusy=true;
                sendMsgThreadHandler.sendEmptyMessage(SEND_CONTINUE);
                break;
            case TRANS_ID_END:
                send_full_page = true;
                break;
            case TRANS_ID_EMPTY:
                //                 pebbleBusy=true;
                sendMsgThreadHandler.sendEmptyMessage(SEND_CONTINUE);
                break;
            case TRANS_ID_TEST: {
                break;
            }
            }
        }
    });

    PebbleKit.registerReceivedNackHandler(_contex, new PebbleKit.PebbleNackReceiver(Constants.PEBBLE_UUID) {
        @Override
        public void receiveNack(Context context, int transactionId) {
            Constants.log(TAG_NAME, "Get a receivedNack:" + String.valueOf(transactionId));
            if (PebbleKit.isWatchConnected(_contex)) {
                switch (transactionId) {
                case TRANS_ID_COMMON:
                    sendMsgThreadHandler.sendEmptyMessage(SEND_CONTINUE);
                    break;
                case TRANS_ID_END:
                    send_full_page = true;
                    break;
                case TRANS_ID_EMPTY:
                    //                   appStatue=0;
                    sendMsgThreadHandler.sendEmptyMessage(SEND_OPEN_APP);
                    break;
                case TRANS_ID_TEST: {
                    Intent inner_intent = new Intent(SetupFragment.class.getName());
                    inner_intent.putExtra(Constants.BROADCAST_VERSION, new byte[] { 0, 0, 0 });
                    LocalBroadcastManager.getInstance(context).sendBroadcast(inner_intent);
                }
                }
            } else {
                sendMsgThreadHandler.sendEmptyMessage(SEND_CLOSE_APP);
            }

        }
    });

    PebbleKit.registerPebbleConnectedReceiver(_contex, new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            isPebbleEnable = true;
        }
    });

    PebbleKit.registerPebbleDisconnectedReceiver(_contex, new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            isPebbleEnable = false;
            sendMsgThreadHandler.sendEmptyMessage(SEND_CLOSE_APP);
        }
    });

    BroadcastReceiver br = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            int command = intent.getIntExtra(Constants.BROADCAST_COMMAND, Constants.BROADCAST_PREFER_CHANGED);

            switch (command) {
            case Constants.BROADCAST_PREFER_CHANGED:
                loadPref();
                break;
            case Constants.BROADCAST_CALL_IDLE:
                if (callEnable) {
                    sendMsgThreadHandler.sendEmptyMessage(SEND_CALL_END);
                }
                break;
            case Constants.BROADCAST_CALL_HOOK:
                if (callEnable) {
                    sendMsgThreadHandler.sendEmptyMessage(SEND_CALL_HOOK);
                }
                break;
            case Constants.BROADCAST_PEBBLE_TEST:
                if (isPebbleEnable) {
                    prepareThreadHandler.sendEmptyMessage(PREPARE_TEST);
                }
                break;
            }
        }
    };
    IntentFilter intentFilter = new IntentFilter(PebbleCenter.class.getName());
    LocalBroadcastManager.getInstance(getApplicationContext()).registerReceiver(br, intentFilter);
}

From source file:com.kanchi.periyava.old.Activity.MainActivity.java

/**
 * Performs the actual navigation logic, updating the main content fragment.
 *///from  w w w .  j  a va 2s.  c  o m
private void navigate(final int itemId) {
    Bundle bundle = new Bundle();
    MenuItem item;
    Message msg = Message.obtain();
    switch (itemId) {
    case R.id.about_peetham:
        msg.what = ConstValues.ABOUT_PEETHAM;
        getFlowHandler().sendMessage(msg);
        break;
    case R.id.about_acharays:
        msg.what = ConstValues.ABOUT_ACHARAYAS;
        getFlowHandler().sendMessage(msg);
        break;

    case R.id.aboutus:
        msg.what = ConstValues.ABOUT_US;
        getFlowHandler().sendMessage(msg);
        break;

    case R.id.privacy:
        msg.what = ConstValues.PRIVACY_POLICY;
        getFlowHandler().sendMessage(msg);
        break;

    case R.id.feedback:
        msg.what = ConstValues.HELP_FEEDBACK;
        getFlowHandler().sendMessage(msg);
        break;
    case R.id.exit:
        android.os.Process.killProcess(android.os.Process.myPid());
        break;
    case R.id.signin:
        msg.what = ConstValues.LOGIN;
        getFlowHandler().sendMessage(msg);
        break;
    case R.id.signout:
        super.ShowMessage(MessageDisplay.DO_YOU_WANT_EXIT, new DialogActionCallback() {
            @Override
            public void onOKClick(String errorCode) {
                Message msg = Message.obtain();
                msg.what = ConstValues.DASHBOARD_WITHOUT_LOGIN;
                getFlowHandler().sendMessage(msg);
            }

            @Override
            public void onCancelClick(String errorCode) {

            }
        });

        break;
    case R.id.dashboard:
        if (UserProfile.getUserProfile().isLoggedIn) {
            msg.what = ConstValues.DASHBOARD_LOGIN;

        } else {
            msg.what = ConstValues.DASHBOARD_WITHOUT_LOGIN;

        }
        getFlowHandler().sendMessage(msg);
        break;
    case R.id.books:
        msg.what = ConstValues.BOOKS_LIST;
        getFlowHandler().sendMessage(msg);
        break;
    /*case R.id.devithinkural:
      msg.what = ConstValues.DEIVATHIN_KURAL;
      getFlowHandler().sendMessage(msg);
      break;*/
    case R.id.satsang:
        if (UserProfile.getUserProfile().isLoggedIn) {
            msg.what = ConstValues.SATSANG_LIST_LOGIN;

        } else {
            msg.what = ConstValues.SATSANG_LIST_WITHOUT_LOGIN;

        }
        getFlowHandler().sendMessage(msg);

        break;
    case R.id.japam:
        if (UserProfile.getInstance().isjoinedsatsang == true) {
            super.showFragment(new Japam(), null, R.id.content, true, Japam.TAG);
        } else {
            ShowSnackBar(context, getWindow().getDecorView(), getResources().getString(R.string.err_not_joined),
                    null, null);
        }
        break;
    case R.id.radio:
        if (!NetworkConnection.isConnected(context)) {
            msg.what = ConstValues.ERROR_INTERNET_CONNECTION;
            getFlowHandler().sendMessage(msg);

        } else {
            item = globalmenu.findItem(R.id.radio);
            item.setVisible(true);
            msg.what = ConstValues.RADIO;
            getFlowHandler().sendMessage(msg);
        }
        break;
    case R.id.gallery:
        msg.what = ConstValues.PHOTO_LIST;
        getFlowHandler().sendMessage(msg);
        break;
    case R.id.videos:
        msg.what = ConstValues.VIDEO_LIST;
        getFlowHandler().sendMessage(msg);
        break;

    /*case R.id.setting:
      super.showFragment(new Setting(), null, R.id.content, true, Setting.TAG);
      break;
            
    case R.id.about:
      super.showFragment(mAbout, null, R.id.content, true, mAbout.TAG);
      break;
      */
    default:
        // ignore
        break;
    }
}

From source file:me.originqiu.library.Thunder.java

private void executeCall(final Integer id) {
    if (taskMap.containsKey(id)) {
        final Message message = Message.obtain();
        try {/*from  w  ww  . ja va2  s. c  o  m*/
            Call call = taskMap.get(id);
            call.enqueue(new Callback() {
                @Override
                public void onFailure(Call call, IOException e) {
                    message.what = MESSAGE_BROKEN;
                    message.obj = new Holder(id, e);
                    post(message);
                }

                @Override
                public void onResponse(Call call, Response response) throws IOException {
                    message.what = MESSAGE_FINISH;
                    message.obj = new Holder(id, new ResponseData.Builder().code(response.code())
                            .message(response.message()).body(response.body().string()).build());
                    post(message);
                }
            });

        } catch (Exception e) {
            message.what = MESSAGE_BROKEN;
            message.obj = new Holder(id, e);
            post(message);
        }
    }
}

From source file:net.networksaremadeofstring.rhybudd.DeviceList.java

public void Refresh() {
    if (dialog != null) {
        dialog.setTitle("Contacting Zenoss...");
        dialog.setMessage("Please wait:\nLoading Infrastructure....");
        dialog.setCancelable(false);/* ww w. j a  v  a  2  s.c om*/

        if (!dialog.isShowing()) {
            dialog.show();
        }
    } else {
        dialog = new ProgressDialog(this);
        dialog.setTitle("Contacting Zenoss...");
        dialog.setMessage("Please wait:\nLoading Infrastructure....");
        dialog.setCancelable(false);
        dialog.show();
    }

    if (listOfZenossDevices != null)
        listOfZenossDevices.clear();

    ((Thread) new Thread() {
        public void run() {
            String MessageExtra = "";
            try {
                Message msg = new Message();
                Bundle bundle = new Bundle();

                ZenossAPI API = null;
                try {

                    if (PreferenceManager.getDefaultSharedPreferences(DeviceList.this)
                            .getBoolean(ZenossAPI.PREFERENCE_IS_ZAAS, false)) {
                        API = new ZenossAPIZaas();
                    } else {
                        API = new ZenossAPICore();
                    }

                    ZenossCredentials credentials = new ZenossCredentials(DeviceList.this);
                    API.Login(credentials);
                } catch (ConnectTimeoutException cte) {
                    if (cte.getMessage() != null) {

                        bundle.putString("exception",
                                "The connection timed out;\r\n" + cte.getMessage().toString());
                        msg.setData(bundle);
                        msg.what = 0;
                        handler.sendMessage(msg);
                        //Toast.makeText(DeviceList.this, "The connection timed out;\r\n" + cte.getMessage().toString(), Toast.LENGTH_LONG).show();
                    } else {
                        bundle.putString("exception",
                                "A time out error was encountered but the exception thrown contains no further information.");
                        msg.setData(bundle);
                        msg.what = 0;
                        handler.sendMessage(msg);
                        //Toast.makeText(DeviceList.this, "A time out error was encountered but the exception thrown contains no further information.", Toast.LENGTH_LONG).show();
                    }
                } catch (Exception e) {
                    if (e.getMessage() != null) {
                        bundle.putString("exception",
                                "An error was encountered;\r\n" + e.getMessage().toString());
                        msg.setData(bundle);
                        msg.what = 0;
                        handler.sendMessage(msg);
                        //Toast.makeText(DeviceList.this, "An error was encountered;\r\n" + e.getMessage().toString(), Toast.LENGTH_LONG).show();
                    } else {
                        bundle.putString("exception",
                                "An error was encountered but the exception thrown contains no further information.");
                        msg.setData(bundle);
                        msg.what = 0;
                        handler.sendMessage(msg);
                        //Toast.makeText(DeviceList.this, "An error was encountered but the exception thrown contains no further information.", Toast.LENGTH_LONG).show();
                    }
                }

                try {
                    if (API != null) {
                        listOfZenossDevices = API.GetRhybuddDevices();
                    } else {
                        listOfZenossDevices = null;
                    }
                } catch (Exception e) {
                    if (e.getMessage() != null)
                        MessageExtra = e.getMessage();

                    listOfZenossDevices = null;
                }

                if (listOfZenossDevices != null && listOfZenossDevices.size() > 0) {
                    DeviceCount = listOfZenossDevices.size();
                    Message.obtain();
                    handler.sendEmptyMessage(1);

                    RhybuddDataSource datasource = new RhybuddDataSource(DeviceList.this);
                    datasource.open();
                    datasource.UpdateRhybuddDevices(listOfZenossDevices);
                    datasource.close();
                } else {
                    //Message msg = new Message();
                    //Bundle bundle = new Bundle();
                    bundle.putString("exception",
                            "A query to both the local DB and Zenoss API returned no devices. " + MessageExtra);
                    msg.setData(bundle);
                    msg.what = 0;
                    handler.sendMessage(msg);
                }

            } catch (Exception e) {
                //BugSenseHandler.log("DeviceList", e);
                Message msg = new Message();
                Bundle bundle = new Bundle();
                bundle.putString("exception", e.getMessage());
                msg.setData(bundle);
                msg.what = 0;
                handler.sendMessage(msg);
            }
        }
    }).start();
}

From source file:org.sufficientlysecure.keychain.service.PassphraseCacheService.java

/**
 * Executed when service is started by intent
 *//*from www.ja  v a 2s . co  m*/
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    Log.d(TAG, "onStartCommand()");

    // register broadcastreceiver
    registerReceiver();

    if (intent != null && intent.getAction() != null) {
        if (ACTION_PASSPHRASE_CACHE_ADD.equals(intent.getAction())) {
            long ttl = intent.getLongExtra(EXTRA_TTL, DEFAULT_TTL);
            long keyId = intent.getLongExtra(EXTRA_KEY_ID, -1);
            String passphrase = intent.getStringExtra(EXTRA_PASSPHRASE);

            Log.d(TAG, "Received ACTION_PASSPHRASE_CACHE_ADD intent in onStartCommand() with keyId: " + keyId
                    + ", ttl: " + ttl);

            // add keyId and passphrase to memory
            mPassphraseCache.put(keyId, passphrase);

            if (ttl > 0) {
                // register new alarm with keyId for this passphrase
                long triggerTime = new Date().getTime() + (ttl * 1000);
                AlarmManager am = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE);
                am.set(AlarmManager.RTC_WAKEUP, triggerTime, buildIntent(this, keyId));
            }
        } else if (ACTION_PASSPHRASE_CACHE_GET.equals(intent.getAction())) {
            long keyId = intent.getLongExtra(EXTRA_KEY_ID, -1);
            Messenger messenger = intent.getParcelableExtra(EXTRA_MESSENGER);

            String passphrase = getCachedPassphraseImpl(keyId);

            Message msg = Message.obtain();
            Bundle bundle = new Bundle();
            bundle.putString(EXTRA_PASSPHRASE, passphrase);
            msg.obj = bundle;
            try {
                messenger.send(msg);
            } catch (RemoteException e) {
                Log.e(Constants.TAG, "Sending message failed", e);
            }
        } else {
            Log.e(Constants.TAG, "Intent or Intent Action not supported!");
        }
    }

    return START_STICKY;
}

From source file:com.aoeng.degu.utils.net.asyncthhpclient.AsyncHttpResponseHandler.java

/**
 * Helper method to create Message instance from handler
 *
 * @param responseMessageId   constant to identify Handler message
 * @param responseMessageData object to be passed to message receiver
 * @return Message instance, should not be null
 *//*from   w  w w  .j av a  2  s. c  o m*/
protected Message obtainMessage(int responseMessageId, Object responseMessageData) {
    Message msg;
    if (handler != null) {
        msg = handler.obtainMessage(responseMessageId, responseMessageData);
    } else {
        msg = Message.obtain();
        if (msg != null) {
            msg.what = responseMessageId;
            msg.obj = responseMessageData;
        }
    }
    return msg;
}

From source file:com.leo.runningman.ui.ImageDetailFragment.java

public boolean sendHandlerMessage(int what, int arg1, int arg2, Object obj) {
    Message msg = Message.obtain();
    if (msg != null) {
        msg.what = what;//  www  .j a v a2s.  co m
        msg.arg1 = arg1;
        msg.arg2 = arg2;
        msg.obj = obj;
        return mHandler.sendMessage(msg);
    }
    return false;
}