List of usage examples for android.os Messenger Messenger
public Messenger(IBinder target)
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 ww w . ja va 2s . c om _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.money.manager.ex.sync.SyncManager.java
public void invokeSyncService(String action) { // Validation. String remoteFile = getRemotePath(); // We need a value in remote file name preferences. if (TextUtils.isEmpty(remoteFile)) return;/*from w w w.j a v a2 s .co m*/ // Action ProgressDialog progressDialog = null; // Create progress dialog only if called from the UI. if ((getContext() instanceof Activity)) { //progress dialog shown only when downloading an updated db file. progressDialog = new ProgressDialog(getContext()); progressDialog.setCancelable(false); progressDialog.setMessage(getContext().getString(R.string.syncProgress)); progressDialog.setIndeterminate(true); // progressDialog.show(); } Messenger messenger = null; if (getContext() instanceof Activity) { // Messenger handles received messages from the sync service. Can run only in a looper thread. messenger = new Messenger(new SyncServiceMessageHandler(getContext(), progressDialog, remoteFile)); } String localFile = getDatabases().getCurrent().localPath; Intent syncServiceIntent = IntentFactory.getSyncServiceIntent(getContext(), action, localFile, remoteFile, messenger); // start service getContext().startService(syncServiceIntent); // Reset any other scheduled uploads as the current operation will modify the files. abortScheduledUpload(); // The messages from the service are received via messenger. }
From source file:org.thialfihar.android.apg.ui.CertifyKeyActivity.java
private void showPassphraseDialog(final long secretKeyId) { // Message is received after passphrase is cached Handler returnHandler = new Handler() { @Override//from w w w . j a v a 2 s .co m public void handleMessage(Message message) { if (message.what == PassphraseDialogFragment.MESSAGE_OKAY) { startSigning(); } } }; // Create a new Messenger for the communication back Messenger messenger = new Messenger(returnHandler); try { PassphraseDialogFragment passphraseDialog = PassphraseDialogFragment.newInstance(this, messenger, secretKeyId); passphraseDialog.show(getSupportFragmentManager(), "passphraseDialog"); } catch (PgpGeneralException e) { Log.d(Constants.TAG, "No passphrase for this secret key!"); // send message to handler to start certification directly returnHandler.sendEmptyMessage(PassphraseDialogFragment.MESSAGE_OKAY); } }
From source file:com.nbplus.iotlib.IoTInterface.java
private IoTInterface() { handlerThread = new HandlerThread("IPChandlerThread"); handlerThread.start();/*from w w w .j a v a2 s . c om*/ mHandler = new IoTInterfaceHandler(handlerThread); mClientMessenger = new Messenger(mHandler); }
From source file:org.sufficientlysecure.keychain.ui.EncryptMessageFragment.java
private void encryptStart(final boolean toClipboard) { // Send all information needed to service to edit key in other thread Intent intent = new Intent(getActivity(), KeychainIntentService.class); intent.setAction(KeychainIntentService.ACTION_ENCRYPT_SIGN); // fill values for this action Bundle data = new Bundle(); data.putInt(KeychainIntentService.TARGET, KeychainIntentService.TARGET_BYTES); String message = mMessage.getText().toString(); if (mEncryptInterface.isModeSymmetric()) { Log.d(Constants.TAG, "Symmetric encryption enabled!"); String passphrase = mEncryptInterface.getPassphrase(); if (passphrase.length() == 0) { passphrase = null;/*from w w w . j av a 2 s .c o m*/ } data.putString(KeychainIntentService.ENCRYPT_SYMMETRIC_PASSPHRASE, passphrase); } else { data.putLong(KeychainIntentService.ENCRYPT_SIGNATURE_KEY_ID, mEncryptInterface.getSignatureKey()); data.putLongArray(KeychainIntentService.ENCRYPT_ENCRYPTION_KEYS_IDS, mEncryptInterface.getEncryptionKeys()); boolean signOnly = (mEncryptInterface.getEncryptionKeys() == null || mEncryptInterface.getEncryptionKeys().length == 0); if (signOnly) { message = fixBadCharactersForGmail(message); } } data.putByteArray(KeychainIntentService.ENCRYPT_MESSAGE_BYTES, message.getBytes()); data.putBoolean(KeychainIntentService.ENCRYPT_USE_ASCII_ARMOR, true); int compressionId = Preferences.getPreferences(getActivity()).getDefaultMessageCompression(); data.putInt(KeychainIntentService.ENCRYPT_COMPRESSION_ID, compressionId); intent.putExtra(KeychainIntentService.EXTRA_DATA, data); // Message is received after encrypting is done in KeychainIntentService KeychainIntentServiceHandler saveHandler = new KeychainIntentServiceHandler(getActivity(), getString(R.string.progress_encrypting), ProgressDialog.STYLE_HORIZONTAL) { public void handleMessage(Message message) { // handle messages by standard KeychainIntentServiceHandler first super.handleMessage(message); if (message.arg1 == KeychainIntentServiceHandler.MESSAGE_OKAY) { // get returned data bundle Bundle data = message.getData(); String output = new String(data.getByteArray(KeychainIntentService.RESULT_BYTES)); Log.d(Constants.TAG, "output: " + output); if (toClipboard) { ClipboardReflection.copyToClipboard(getActivity(), output); AppMsg.makeText(getActivity(), R.string.encrypt_sign_clipboard_successful, AppMsg.STYLE_INFO).show(); } else { Intent sendIntent = new Intent(Intent.ACTION_SEND); // Type is set to text/plain so that encrypted messages can // be sent with Whatsapp, Hangouts, SMS etc... sendIntent.setType("text/plain"); sendIntent.putExtra(Intent.EXTRA_TEXT, output); startActivity(Intent.createChooser(sendIntent, getString(R.string.title_share_with))); } } } }; // Create a new Messenger for the communication back Messenger messenger = new Messenger(saveHandler); intent.putExtra(KeychainIntentService.EXTRA_MESSENGER, messenger); // show progress dialog saveHandler.showProgressDialog(getActivity()); // start service with intent getActivity().startService(intent); }
From source file:org.ymkm.lib.controller.support.ControlledDialogFragment.java
@Override public final Messenger getMessenger() { return new Messenger(mHandler); }
From source file:org.sufficientlysecure.keychain.ui.SafeSlingerActivity.java
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == REQUEST_CODE_SAFE_SLINGER) { if (resultCode == ExchangeActivity.RESULT_EXCHANGE_CANCELED) { return; }/*from w w w. ja v a 2 s . c om*/ final FragmentActivity activity = SafeSlingerActivity.this; // Message is received after importing is done in KeychainIntentService KeychainIntentServiceHandler saveHandler = new KeychainIntentServiceHandler(activity, getString(R.string.progress_importing), ProgressDialog.STYLE_HORIZONTAL, true) { public void handleMessage(Message message) { // handle messages by standard KeychainIntentServiceHandler first super.handleMessage(message); if (message.arg1 == KeychainIntentServiceHandler.MESSAGE_OKAY) { // get returned data bundle Bundle returnData = message.getData(); if (returnData == null) { return; } final ImportKeyResult result = returnData.getParcelable(OperationResult.EXTRA_RESULT); if (result == null) { Log.e(Constants.TAG, "result == null"); return; } if (!result.success()) { // result.createNotify(activity).show(); // only return if no success... Intent data = new Intent(); data.putExtras(returnData); setResult(RESULT_OK, data); finish(); return; } // if (mExchangeMasterKeyId == null) { // return; // } Intent certifyIntent = new Intent(activity, CertifyKeyActivity.class); certifyIntent.putExtra(CertifyKeyActivity.EXTRA_RESULT, result); certifyIntent.putExtra(CertifyKeyActivity.EXTRA_KEY_IDS, result.getImportedMasterKeyIds()); certifyIntent.putExtra(CertifyKeyActivity.EXTRA_CERTIFY_KEY_ID, mMasterKeyId); startActivityForResult(certifyIntent, KeyListActivity.REQUEST_CODE_RESULT_TO_LIST); // mExchangeMasterKeyId = null; } } }; Log.d(Constants.TAG, "importKeys started"); // Send all information needed to service to import key in other thread Intent intent = new Intent(activity, KeychainIntentService.class); intent.setAction(KeychainIntentService.ACTION_IMPORT_KEYRING); // instead of giving the entries by Intent extra, cache them into a // file to prevent Java Binder problems on heavy imports // read FileImportCache for more info. try { // import exchanged keys ArrayList<ParcelableKeyRing> it = getSlingedKeys(data.getExtras()); // We parcel this iteratively into a file - anything we can // display here, we should be able to import. ParcelableFileCache<ParcelableKeyRing> cache = new ParcelableFileCache<ParcelableKeyRing>(activity, "key_import.pcl"); cache.writeCache(it.size(), it.iterator()); // fill values for this action Bundle bundle = new Bundle(); intent.putExtra(KeychainIntentService.EXTRA_DATA, bundle); // Create a new Messenger for the communication back Messenger messenger = new Messenger(saveHandler); intent.putExtra(KeychainIntentService.EXTRA_MESSENGER, messenger); // show progress dialog saveHandler.showProgressDialog(activity); // start service with intent activity.startService(intent); } catch (IOException e) { Log.e(Constants.TAG, "Problem writing cache file", e); Notify.showNotify(activity, "Problem writing cache file!", Notify.Style.ERROR); } } else { // give everything else down to KeyListActivity! setResult(resultCode, data); finish(); } }
From source file:by.zatta.pilight.MainActivity.java
@Override public void onServiceConnected(ComponentName name, IBinder service) { mServiceMessenger = new Messenger(service); try {/*from w w w .j a v a2 s. com*/ Message msg = Message.obtain(null, ConnectionService.MSG_REGISTER_CLIENT); msg.replyTo = mMessenger; mServiceMessenger.send(msg); } catch (RemoteException e) { // In this case the service has crashed before we could even do // anything with it } }
From source file:org.thialfihar.android.apg.ui.EncryptMessageFragment.java
private void encryptStart(final boolean toClipboard) { // Send all information needed to service to edit key in other thread Intent intent = new Intent(getActivity(), ApgIntentService.class); intent.setAction(ApgIntentService.ACTION_ENCRYPT_SIGN); // fill values for this action Bundle data = new Bundle(); data.putInt(ApgIntentService.TARGET, ApgIntentService.TARGET_BYTES); String message = mMessage.getText().toString(); if (mEncryptInterface.isModeSymmetric()) { Log.d(Constants.TAG, "Symmetric encryption enabled!"); String passphrase = mEncryptInterface.getPassphrase(); if (passphrase.length() == 0) { passphrase = null;//from w ww. j a v a 2 s . co m } data.putString(ApgIntentService.ENCRYPT_SYMMETRIC_PASSPHRASE, passphrase); } else { data.putLong(ApgIntentService.ENCRYPT_SIGNATURE_KEY_ID, mEncryptInterface.getSignatureKey()); data.putLongArray(ApgIntentService.ENCRYPT_ENCRYPTION_KEYS_IDS, mEncryptInterface.getEncryptionKeys()); boolean signOnly = (mEncryptInterface.getEncryptionKeys() == null || mEncryptInterface.getEncryptionKeys().length == 0); if (signOnly) { message = fixBadCharactersForGmail(message); } } data.putByteArray(ApgIntentService.ENCRYPT_MESSAGE_BYTES, message.getBytes()); data.putBoolean(ApgIntentService.ENCRYPT_USE_ASCII_ARMOR, true); int compressionId = Preferences.getPreferences(getActivity()).getDefaultMessageCompression(); data.putInt(ApgIntentService.ENCRYPT_COMPRESSION_ID, compressionId); intent.putExtra(ApgIntentService.EXTRA_DATA, data); final Activity activity = getActivity(); // Message is received after encrypting is done in ApgIntentService ApgIntentServiceHandler saveHandler = new ApgIntentServiceHandler(getActivity(), getString(R.string.progress_encrypting), ProgressDialog.STYLE_HORIZONTAL) { public void handleMessage(Message message) { // handle messages by standard ApgIntentServiceHandler first super.handleMessage(message); if (message.arg1 == ApgIntentServiceHandler.MESSAGE_OKAY) { // get returned data bundle Bundle data = message.getData(); String output = new String(data.getByteArray(ApgIntentService.RESULT_BYTES)); Log.d(Constants.TAG, "output: " + output); if (mLegacyMode) { Intent result = new Intent(); result.putExtra("encryptedMessage", output); activity.setResult(activity.RESULT_OK, result); activity.finish(); return; } else if (toClipboard) { ClipboardReflection.copyToClipboard(getActivity(), output); AppMsg.makeText(getActivity(), R.string.encrypt_sign_clipboard_successful, AppMsg.STYLE_INFO).show(); } else { Intent sendIntent = new Intent(Intent.ACTION_SEND); // Type is set to text/plain so that encrypted messages can // be sent with Whatsapp, Hangouts, SMS etc... sendIntent.setType("text/plain"); sendIntent.putExtra(Intent.EXTRA_TEXT, output); startActivity(Intent.createChooser(sendIntent, getString(R.string.title_share_with))); } } } }; // Create a new Messenger for the communication back Messenger messenger = new Messenger(saveHandler); intent.putExtra(ApgIntentService.EXTRA_MESSENGER, messenger); // show progress dialog saveHandler.showProgressDialog(getActivity()); // start service with intent getActivity().startService(intent); }
From source file:com.example.contactslist.ui.ContactsListFragment.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Check if this fragment is part of a two-pane set up or a single pane by reading a // boolean from the application resource directories. This lets allows us to easily specify // which screen sizes should use a two-pane layout by setting this boolean in the // corresponding resource size-qualified directory. mIsTwoPaneLayout = getResources().getBoolean(R.bool.has_two_panes); // Let this fragment contribute menu items setHasOptionsMenu(true);/*from w w w . ja v a 2 s. c om*/ // Create the main contacts adapter mAdapter = new ContactsAdapter(getActivity()); if (dbHelper == null) dbHelper = new AppContactsHelper(getActivity()); if (savedInstanceState != null) { // If we're restoring state after this fragment was recreated then // retrieve previous search term and previously selected search // result. mSearchTerm = savedInstanceState.getString(SearchManager.QUERY); mPreviouslySelectedSearchItem = savedInstanceState.getInt(STATE_PREVIOUSLY_SELECTED_KEY, 0); } /* * An ImageLoader object loads and resizes an image in the background and binds it to the * QuickContactBadge in each item layout of the ListView. ImageLoader implements memory * caching for each image, which substantially improves refreshes of the ListView as the * user scrolls through it. * * To learn more about downloading images asynchronously and caching the results, read the * Android training class Displaying Bitmaps Efficiently. * * http://developer.android.com/training/displaying-bitmaps/ */ mImageLoader = new ImageLoader(getActivity(), getListPreferredItemHeight()) { @Override protected Bitmap processBitmap(Object data) { // This gets called in a background thread and passed the data from // ImageLoader.loadImage(). return loadContactPhotoThumbnail((String) data, getImageSize()); } }; // Set a placeholder loading image for the image loader mImageLoader.setLoadingImage(R.drawable.ic_contact_picture_holo_light); // Add a cache to the image loader mImageLoader.addImageCache(getActivity().getSupportFragmentManager(), 0.1f); //Setup the handler //mHandler = new Handler(Looper.getMainLooper()); Intent lIntent = new Intent(getActivity(), StringAppService.class); // Initialize a new Messenger and pass it to service mContactListMessenger = new Messenger(new IncomingHandler()); lIntent.putExtra("Messenger", mContactListMessenger); getActivity().startService(lIntent); }