List of usage examples for android.os Message obtain
public static Message obtain(Handler h, int what)
From source file:Main.java
static Message obtain(Handler handler, Runnable runnable, Object obj, int what) { Message msg = Message.obtain(handler, runnable); msg.obj = obj;/*from w w w . ja v a 2 s . c om*/ msg.arg1 = -1; msg.arg2 = -1; msg.replyTo = null; msg.setData(null); msg.what = what; return msg; }
From source file:Main.java
public static void sendMsg2Client(int iMsg, int arg1, int arg2, Bundle extras) { if (mMessenger == null) { return;/*w ww . j av a 2 s .c o m*/ } try { Message msgBack = Message.obtain(null, iMsg); if (msgBack != null) { msgBack.arg1 = arg1; msgBack.arg2 = arg2; msgBack.setData(extras); mMessenger.send(msgBack); } } catch (RemoteException e) { e.printStackTrace(); } }
From source file:Main.java
public static void sendMsg2Client(Messenger messenger, String sKey, String sObjParam, int iMsg) { if (messenger == null) { return;/*www. ja v a2 s . c o m*/ } try { Bundle b = new Bundle(); if (null != sKey) { b.putString(sKey, sObjParam); } Message msgBack = Message.obtain(null, iMsg); if (msgBack != null) { msgBack.setData(b); messenger.send(msgBack); } } catch (RemoteException e) { e.printStackTrace(); } }
From source file:es.upm.dit.gsi.noticiastvi.gtv.item.FavoriteThread.java
@Override public void run() { if (doFavorite()) { handler.sendMessage(Message.obtain(handler, RESULT_OK)); } else {/*www . ja v a2s .c om*/ handler.sendMessage(Message.obtain(handler, RESULT_ERROR)); } }
From source file:curt.android.book.NetworkWorker.java
public void run() { try {//from www.j a v a 2s. c o m // These return a JSON result which describes if and where the query was found. This API may // break or disappear at any time in the future. Since this is an API call rather than a // website, we don't use LocaleManager to change the TLD. String uri; if (LocaleManager.isBookSearchUrl(isbn)) { int equals = isbn.indexOf('='); String volumeId = isbn.substring(equals + 1); uri = "http://www.google.com/books?id=" + volumeId + "&jscmd=SearchWithinVolume2&q=" + query; } else { uri = "http://www.google.com/books?vid=isbn" + isbn + "&jscmd=SearchWithinVolume2&q=" + query; } try { String content = HttpHelper.downloadViaHttp(uri, HttpHelper.ContentType.JSON); JSONObject json = new JSONObject(content); Message message = Message.obtain(handler, R.id.search_book_contents_succeeded); message.obj = json; message.sendToTarget(); } catch (IOException ioe) { Message message = Message.obtain(handler, R.id.search_book_contents_failed); message.sendToTarget(); } } catch (JSONException je) { Log.w(TAG, "Error accessing book search", je); Message message = Message.obtain(handler, R.id.search_book_contents_failed); message.sendToTarget(); } }
From source file:nl.pilight.illumina.activity.LocationListActivity.java
@Override public void onServiceConnected() { super.onServiceConnected(); dispatch(Message.obtain(null, PilightService.Request.STATE)); }
From source file:eu.esu.mobilecontrol2.sdk.MessageServiceFragment.java
@Override public void onDestroy() { if (mServiceBound) { final Message message = Message.obtain(null, MSG_UNREGISTER_CLIENT); message.replyTo = mReceiver;/*from w ww.j av a 2 s .c o m*/ sendMessage(message); getActivity().unbindService(mConnection); } super.onDestroy(); }
From source file:com.google.zxing.client.android.book.NetworkWorker.java
@Override public void run() { try {/*ww w . j ava 2s . c o m*/ // These return a JSON result which describes if and where the query was found. This API may // break or disappear at any time in the future. Since this is an API call rather than a // website, we don't use LocaleManager to change the TLD. String uri; if (LocaleManager.isBookSearchUrl(isbn)) { int equals = isbn.indexOf('='); String volumeId = isbn.substring(equals + 1); uri = "http://www.google.com/books?id=" + volumeId + "&jscmd=SearchWithinVolume2&q=" + query; } else { uri = "http://www.google.com/books?vid=isbn" + isbn + "&jscmd=SearchWithinVolume2&q=" + query; } try { String content = HttpHelper.downloadViaHttp(uri, HttpHelper.ContentType.JSON); JSONObject json = new JSONObject(content); Message message = Message.obtain(handler, R.id.search_book_contents_succeeded); message.obj = json; message.sendToTarget(); } catch (IOException ioe) { Message message = Message.obtain(handler, R.id.search_book_contents_failed); message.sendToTarget(); } } catch (JSONException je) { Log.w(TAG, "Error accessing book search", je); Message message = Message.obtain(handler, R.id.search_book_contents_failed); message.sendToTarget(); } }
From source file:nl.pilight.illumina.activity.LocationListActivity.java
private void requestLocations() { log.info("requestLocations"); dispatch(Message.obtain(null, PilightService.Request.LOCATION_LIST)); }
From source file:org.trace.tracker.Tracker.java
/** * Initiates the location and activity tracking modules. * <br>//from w w w. j a v a 2s . c o m * <br><b>Note:</b> It is important to assure in API version above 23, that the ACCESS_FINE_LOCATION * and ACCESS_COARSE_LOCATION have been granted, and otherwise, request them. * */ public void startTracking() { String id = mTrackStorage.getNextAvailableId(); synchronized (trackLock) { mCurrentTrack = id; } Message msg = Message.obtain(null, TRACETrackerService.TRACETrackerOperations.TRACK_ACTION); sendRequest(msg); LocalBroadcastManager.getInstance(mContext).registerReceiver(mLocationBroadcastReceiver, mLocationBroadcastReceiver.getLocationBroadcastIntentFilter()); }