Skip to content

Instantly share code, notes, and snippets.

@rajuashok
Created October 31, 2013 03:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rajuashok/7243840 to your computer and use it in GitHub Desktop.
Save rajuashok/7243840 to your computer and use it in GitHub Desktop.
Building HandlerThread for IntentService
public class GCMIntentService extends GCMBaseIntentService {
.
.
.
private Looper mServiceLooper;
public GCMIntentService() {
.
.
.
HandlerThread thread =
new HandlerThread("UmanoGCMIntentService:WorkerThread",
Process.THREAD_PRIORITY_BACKGROUND);
thread.start();
mServiceLooper = thread.getLooper();
}
@Override
protected void onMessage(Context context, Intent intent) {
Handler h = new Handler(mServiceLooper);
h.post(new Runnable() {
@Override
public void run() {
// Execute network fetch here.
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment