Example usage for android.os Handler post

List of usage examples for android.os Handler post

Introduction

In this page you can find the example usage for android.os Handler post.

Prototype

public final boolean post(Runnable r) 

Source Link

Document

Causes the Runnable r to be added to the message queue.

Usage

From source file:com.ferid.app.notetake.MainActivity.java

/**
 * Retrieves from preferences//from   www  .  j  a v  a  2  s  .co  m
 */
private void getText() {
    Handler handler = new Handler();
    handler.post(new Runnable() {
        @Override
        public void run() {
            String note = PrefsUtil.getNote(context);

            writeIntoNote(note);
        }
    });
}

From source file:com.zapto.park.ParkActivity.java

public void updateEmployees() {
    Log.i(LOG_TAG, "Updating employees.");
    Handler handler = new Handler();
    handler.post(new Runnable() {
        @Override//from ww w .j  a  va 2  s .  com
        public void run() {
            loadEmployees();
        }
    });
}

From source file:com.tct.mail.NotificationActionIntentService.java

@Override
protected void onHandleIntent(final Intent intent) {
    final Context context = this;
    final String action = intent.getAction();
    // TS: chao.zhang 2015-09-21 EMAIL FEATURE-585337 ADD_S
    //NOTE: handle the refresh intent.
    if (ACTION_REFRESH.equals(action)) {
        boolean cleanStatus = intent.getBooleanExtra(NotificationUtils.EXTRA_NEED_CLEAN_STATUS, false);
        long boxId = intent.getLongExtra(NotificationUtils.EXTRA_OUTBOX_ID, -1);
        //after click the action,cancel the notification.
        int notificationId = intent.getIntExtra(NotificationUtils.EXTRA_FAIL_NOTIFICATION_ID, 0);
        NotificationManager mNotificationManager = (NotificationManager) context
                .getSystemService(Context.NOTIFICATION_SERVICE);
        mNotificationManager.cancel(notificationId);
        if (boxId == -1) {
            LogUtils.e(LOG_TAG,//  w  w w. j av  a2 s .c o  m
                    "can't find the oubox during handle Intent ACTION_REFRESH in NotificationActionIntentService#onHandleIntent");
            return;
        }
        Uri refreshUri = intent.getData();
        if (cleanStatus && isOutboxNotEmpty(context, boxId)) {
            // 1.clean failed status
            cleanFaildMailStatus(context, boxId);
            // 2.start refresh(sync) the outbox
            context.getContentResolver().query(refreshUri, null, null, null, null);
            // 3. show the sending toast
            // Why add toast to Handler? cause the notificationActionIntentService is
            // asynchronous,so want show toast,
            // only must add toast to Main thread.
            Handler handler = new Handler(Looper.getMainLooper());
            handler.post(new Runnable() {
                @Override
                public void run() {
                    // TODO Auto-generated method stub
                    Toast.makeText(getApplicationContext(), R.string.sending, Toast.LENGTH_SHORT).show();
                }
            });
        }
        return;
    }
    // TS: chao.zhang 2015-09-21 EMAIL FEATURE-585337 ADD_E
    else if (ACTION_CALENDAR_NEVER_ASK_AGAIN.equals(action)) {
        NotificationManager mNotificationManager = (NotificationManager) context
                .getSystemService(Context.NOTIFICATION_SERVICE);
        if (mNotificationManager != null) {
            mNotificationManager.cancel(NotificationController.EXCHANGE_NEWCALENDAR_NOTIFICATION_ID);
        }
        MailPrefs.get(context).setIgnoreExchangeCalendarPermission(true); //TS: zheng.zou 2016-1-22 EMAIL BUGFIX-1431088 ADD
        return;
    } else if (ACTION_CONTACTS_NEVER_ASK_AGAIN.equals(action)) {
        NotificationManager mNotificationManager = (NotificationManager) context
                .getSystemService(Context.NOTIFICATION_SERVICE);
        if (mNotificationManager != null) {
            mNotificationManager.cancel(NotificationController.EXCHANGE_NEWCONTACTS_NOTIFICATION_ID);
        }
        MailPrefs.get(context).setIgnoreExchangeContactPermission(true); //TS: zheng.zou 2016-1-22 EMAIL BUGFIX-1431088 ADD
        return;
    } else if (ACTION_STORAGE_NEVER_ASK_AGAIN.equals(action)) { //TS: zheng.zou 2016-1-22 EMAIL BUGFIX-1431088 ADD_S
        NotificationManager mNotificationManager = (NotificationManager) context
                .getSystemService(Context.NOTIFICATION_SERVICE);
        if (mNotificationManager != null) {
            mNotificationManager.cancel(NotificationController.EXCHANGE_NEWSTORAGE_NOTIFICATION_ID);
        }
        MailPrefs.get(context).setIgnoreExchangeStoragePermission(true);
        //TS: zheng.zou 2016-1-22 EMAIL BUGFIX-1431088 ADD_E
    }
    /*
     * Grab the alarm from the intent. Since the remote AlarmManagerService fills in the Intent
     * to add some extra data, it must unparcel the NotificationAction object. It throws a
     * ClassNotFoundException when unparcelling.
     * To avoid this, do the marshalling ourselves.
     */
    final NotificationAction notificationAction;
    final byte[] data = intent.getByteArrayExtra(EXTRA_NOTIFICATION_ACTION);
    if (data != null) {
        final Parcel in = Parcel.obtain();
        in.unmarshall(data, 0, data.length);
        in.setDataPosition(0);
        notificationAction = NotificationAction.CREATOR.createFromParcel(in,
                NotificationAction.class.getClassLoader());
    } else {
        LogUtils.wtf(LOG_TAG, "data was null trying to unparcel the NotificationAction");
        return;
    }

    final Message message = notificationAction.getMessage();

    final ContentResolver contentResolver = getContentResolver();

    LogUtils.i(LOG_TAG, "Handling %s", action);

    logNotificationAction(action, notificationAction);

    if (notificationAction.getSource() == NotificationAction.SOURCE_REMOTE) {
        // Skip undo if the action is bridged from remote node.  This should be similar to the
        // logic after the Undo notification expires in a regular flow.
        LogUtils.d(LOG_TAG, "Canceling %s", notificationAction.getNotificationId());
        NotificationManagerCompat.from(context).cancel(notificationAction.getNotificationId());
        NotificationActionUtils.processDestructiveAction(this, notificationAction);
        NotificationActionUtils.resendNotifications(context, notificationAction.getAccount(),
                notificationAction.getFolder());
        return;
    }

    if (ACTION_UNDO.equals(action)) {
        NotificationActionUtils.cancelUndoTimeout(context, notificationAction);
        NotificationActionUtils.cancelUndoNotification(context, notificationAction);
    } else if (ACTION_ARCHIVE_REMOVE_LABEL.equals(action) || ACTION_DELETE.equals(action)) {
        // All we need to do is switch to an Undo notification
        NotificationActionUtils.createUndoNotification(context, notificationAction);

        NotificationActionUtils.registerUndoTimeout(context, notificationAction);
    } else {
        if (ACTION_UNDO_TIMEOUT.equals(action) || ACTION_DESTRUCT.equals(action)) {
            // Process the action
            NotificationActionUtils.cancelUndoTimeout(this, notificationAction);
            NotificationActionUtils.processUndoNotification(this, notificationAction);
        } else if (ACTION_MARK_READ.equals(action)) {
            final Uri uri = message.uri;

            final ContentValues values = new ContentValues(1);
            values.put(UIProvider.MessageColumns.READ, 1);

            contentResolver.update(uri, values, null, null);
        }

        NotificationActionUtils.resendNotifications(context, notificationAction.getAccount(),
                notificationAction.getFolder());
    }
}

From source file:emu.project64.SplashActivity.java

public void StartExtraction() {
    if (mInit) {//  w  w  w  . ja v  a  2s.c om
        return;
    }
    mInit = true;
    String ConfigFile = AndroidDevice.PACKAGE_DIRECTORY + "/Config/Project64.cfg";
    if ((new File(ConfigFile)).exists()) {
        InitProject64();
    }

    ((Project64Application) getApplication()).getDefaultTracker().send(
            new HitBuilders.EventBuilder().setCategory("start").setLabel(NativeExports.appVersion()).build());

    // Extract the assets in a separate thread and launch the menu activity
    // Handler.postDelayed ensures this runs only after activity has resumed
    Log.e("Splash", "extractAssetsTaskLauncher - startup");
    final Handler handler = new Handler();
    if (!mAppInit
            || NativeExports.UISettingsLoadDword(UISettingID.Asserts_Version.getValue()) != ASSET_VERSION) {
        handler.post(extractAssetsTaskLauncher);
    } else {
        handler.postDelayed(startGalleryLauncher, SPLASH_DELAY);
    }
}

From source file:com.shivshankar.MyFirebaseMessagingService.java

@Override
public void onMessageReceived(RemoteMessage remoteMessage) {

    Log.d("TAGRK", "From: " + remoteMessage.getFrom());
    String message = "", title = "", strImageURL = "";
    if (remoteMessage.getData() != null && remoteMessage.getData().size() > 0) {
        Log.d("TAGRK", "Message data payload: " + remoteMessage.getData());

        message = "" + remoteMessage.getData().get(Config.MESSAGE_KEY);
        title = "" + remoteMessage.getData().get(Config.TITLE_KEY);
        strImageURL = "" + remoteMessage.getData().get(Config.IMAGE_KEY);
    } else if (remoteMessage.getNotification() != null) {
        Log.d("TAGRK", "Message Notification Body: " + remoteMessage.getNotification().getBody());
        message = "" + remoteMessage.getNotification().getBody();
        title = "" + remoteMessage.getNotification().getTitle();
        strImageURL = "" + remoteMessage.getNotification().getIcon();
    }//from   w ww  .jav a2s .co m

    if (strImageURL != null && !strImageURL.equals("") && !strImageURL.equals("null")) {
        Handler handler = new Handler(Looper.getMainLooper());
        final String finalTitle = title;
        final String finalMessage = message;
        final String finalStrImageURL = strImageURL;
        handler.post(new Runnable() {
            public void run() {
                new ServerAPICallImageBitmap(finalTitle, finalMessage, finalStrImageURL, "").execute();
            }
        });
    } else if (title.equalsIgnoreCase("Logout")) {
        try {
            SharedPreferences.Editor editor = AppPreferences.getPrefs().edit();
            editor.putString(commonVariables.KEY_LOGIN_ID, "0");
            editor.putBoolean(commonVariables.KEY_IS_LOG_IN, false);
            editor.putString(commonVariables.KEY_SELLER_PROFILE, "");
            editor.putString(commonVariables.KEY_BUYER_PROFILE, "");
            editor.putString(commonVariables.KEY_BRAND, "");
            editor.putBoolean(commonVariables.KEY_IS_BRAND, false);
            editor.putBoolean(commonVariables.KEY_IS_SELLER, false);
            editor.putBoolean(commonVariables.KEY_IS_SKIPPED_LOGIN_BUYER, false);
            editor.commit();
            android.os.Process.killProcess(android.os.Process.myPid());
            List<ApplicationInfo> packages;
            PackageManager pm;
            pm = getPackageManager();
            packages = pm.getInstalledApplications(0);

            ActivityManager mActivityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
            String myPackage = getApplicationContext().getPackageName();
            for (ApplicationInfo packageInfo : packages) {
                if ((packageInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 1)
                    continue;
                if (packageInfo.packageName.equals(myPackage))
                    continue;
                mActivityManager.killBackgroundProcesses(packageInfo.packageName);
            }
            mActivityManager.restartPackage(myPackage);
        } catch (Exception e) {
            e.printStackTrace();
        }
    } else
        sendNotification(title, message);
    Log.i("TAGRK", "Received: " + remoteMessage.toString());
}

From source file:com.njlabs.amrita.aid.news.NewsActivity.java

@Override
public void init(Bundle savedInstanceState) {
    setupLayout(R.layout.activity_news, Color.parseColor("#ffc107"));

    swipeRefreshLayout = (ExtendedSwipeRefreshLayout) findViewById(R.id.swipe_refresh_layout);
    recyclerView = (RecyclerView) findViewById(R.id.list);

    swipeRefreshLayout.setColorSchemeColors(Color.parseColor("#ffc107"));
    swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
        @Override//w  w  w  . j  a  v a  2 s. com
        public void onRefresh() {
            getNews(true);
        }
    });
    final LinearLayoutManager layoutParams = new LinearLayoutManager(this);
    recyclerView.setLayoutManager(layoutParams);
    recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
        @Override
        public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
            super.onScrollStateChanged(recyclerView, newState);
        }

        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            super.onScrolled(recyclerView, dx, dy);
        }
    });

    swipeRefreshLayout.setRefreshing(true);

    final Handler uiHandler = new Handler();
    (new Thread(new Runnable() {
        @Override
        public void run() {
            final List<NewsModel> articles = NewsModel.getAll();
            uiHandler.post(new Runnable() {
                @Override
                public void run() {
                    if (articles != null && articles.size() > 0) {
                        recyclerView.setAdapter(new NewsAdapter(articles));
                        swipeRefreshLayout.setRefreshing(false);
                    } else {
                        getNews(false);
                    }
                }
            });
        }
    })).start();

    client = new OkHttpClient.Builder().followRedirects(true).followSslRedirects(true).build();

}

From source file:com.libreteam.taxi.Customer_Fragment_Activity.java

public void didReceiveCode(int code, String string) throws JSONException {
    switch (code) {
    case 0:/*  w w w . j  a v a  2  s. co m*/
        break;
    case 1:
        try {
            ride_id = new JSONObject(string).getJSONObject("info").getString("ride_id").toString();
        } catch (JSONException e) {
            e.printStackTrace();
        }
        break;
    case 2:
    case 3:
        didCancelRide();
        break;
    case 4:
        Taxi_System.testLog(new JSONObject(string).getJSONObject("userinfo"));
        customer_token = new JSONObject(string).getJSONObject("info").getString("token").toString();
        latlng = new JSONObject(string).getJSONObject("userinfo").getString("latlng").toString();
        address = new JSONObject(new JSONObject(string).getString("userinfo")).getString("address");
        Taxi_System.addSystem(context, Customer_Constants.PICK_UP, address + "");
        didReceiveRide(
                new String[] { new JSONObject(string).getJSONObject("info").getString("ride_id").toString(),
                        new JSONObject(string).getJSONObject("info").getString("token").toString(),
                        new JSONObject(string).getJSONObject("userinfo").getString("address").toString(),
                        new JSONObject(string).getJSONObject("userinfo").getString("latlng").toString(),
                        new JSONObject(string).getJSONObject("userinfo").getString("car_model").toString(),
                        new JSONObject(string).getJSONObject("userinfo").getString("time").toString(),
                        new JSONObject(string).getJSONObject("userinfo").getString("username").toString(),
                        new JSONObject(string).getJSONObject("userinfo").getString("taxi_company").toString(),
                        new JSONObject(string).getJSONObject("userinfo").getString("license_plate").toString(),
                        new JSONObject(string).getJSONObject("userinfo").getString("avatar").toString(),
                        new JSONObject(string).getJSONObject("userinfo").getString("des_lat").toString(),
                        new JSONObject(string).getJSONObject("userinfo").getString("des").toString(),
                        new JSONObject(string).getJSONObject("userinfo").getString("start_lat").toString() });
        break;
    case 7:
        didGetCall(new String[] { new JSONObject(string).getJSONObject("userinfo").getString("name").toString(),
                new JSONObject(string).getJSONObject("userinfo").getString("taxi_company").toString(),
                new JSONObject(string).getJSONObject("userinfo").getString("car_model").toString(), ride_id,
                customer_token, latlng,
                new JSONObject(string).getJSONObject("userinfo").getString("des_lat").toString(),
                new JSONObject(string).getJSONObject("userinfo").getString("des_address").toString(),
                new JSONObject(string).getJSONObject("userinfo").getString("start_lat").toString(),
                new JSONObject(string).getJSONObject("userinfo").getString("latlng").toString() });
        break;
    case 11:
        driverLatLng = new LatLng(Double.valueOf(new JSONObject(string).getJSONObject("info").getString("lat")),
                Double.valueOf(new JSONObject(string).getJSONObject("info").getString("lng")));
        Handler handler = new Handler(Looper.getMainLooper());
        handler.post(new Runnable() {
            @Override
            public void run() {
                new Customer_Boarding().didGetPosition(driverLatLng);
                new Customer_Finish_Rating().didGetPosition(driverLatLng);
            }
        });
        break;
    }
}

From source file:com.scooter1556.sms.android.fragment.AudioPlayerFragment.java

@Override
public void onResume() {
    super.onResume();

    // Player control update thread
    executorService = Executors.newSingleThreadScheduledExecutor();

    final Handler handler = new Handler();
    Runnable runnable = new Runnable() {
        @Override/*from w  w w .  j a v  a  2  s  . c o m*/
        public void run() {
            handler.post(new Runnable() {
                @Override
                public void run() {
                    updateProgressBar();
                }
            });
        }
    };
    executorService.scheduleWithFixedDelay(runnable, 0L, 1000L, TimeUnit.MILLISECONDS);

    // Update player controls
    updatePlayerControls();

    // Set current media info
    updateMediaInfo();
}

From source file:com.kaszubski.kamil.emmhelper.MainActivity.java

@Override
public boolean onQueryTextChange(final String newText) {
    Log.v(TAG, "query \"" + newText + "\"");
    Fragment fragment = fragmentManager.findFragmentByTag(Constants.FRAGMENT_SEARCH);
    if (newText.trim().length() > 0) {
        if (progressBar == null && fragment != null)
            progressBar = ((SearchFragment) fragment).getProgressBar();

        if (previousQuery != null && newText.contains(previousQuery)) {
            Log.i(TAG, "similar query true");
            final Handler handler = new Handler();
            handler.post(new Runnable() {
                @Override/*from w  w  w.j  a v  a2 s  .  co  m*/
                public void run() {
                    if (searchPackages.getStatus() == AsyncTask.Status.FINISHED) {
                        searchPackages = new SearchPackages(true);
                        searchPackages.execute(newText);
                    } else {
                        handler.postDelayed(this, 200);
                    }
                }
            });

        } else {
            Log.i(TAG, "similar query false");
            searchResults.clear();
            if (searchPackages != null && searchPackages.getStatus() != AsyncTask.Status.FINISHED) {
                searchPackages.cancel(true);
                progressBar.setVisibility(View.INVISIBLE);
            }

            searchPackages = new SearchPackages();
            searchPackages.execute(newText);
        }
        previousQuery = newText;
        progressBar.setVisibility(View.VISIBLE);

    } else if (fragment != null)
        ((SearchFragment) fragment).setSearchResults(list);
    return true;
}

From source file:com.mch.registry.ccs.app.GcmIntentService.java

@Override
///New: Mueller/*from ww  w . j a v  a  2s .c o m*/
protected void onHandleIntent(Intent intent) {
    mSenderId = Constants.PROJECT_ID;
    GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this);

    // action handling for actions of the activity
    String action = intent.getAction();
    Log.v("PregnancyGuide", "action: " + action);
    if (action.equals(Constants.ACTION_REGISTER)) {
        register(gcm, intent);
    } else if (action.equals(Constants.ACTION_UNREGISTER)) {
        unregister(gcm, intent);
    } else if (action.equals(Constants.ACTION_ECHO)) {
        sendMessage(gcm, intent);
    }

    // handling of stuff as described on
    // http://developer.android.com/google/gcm/client.html
    try {
        Bundle extras = intent.getExtras();
        // The getMessageType() intent parameter must be the intent you
        // received in your BroadcastReceiver.
        String messageType = gcm.getMessageType(intent);

        if (extras != null && !extras.isEmpty()) { // has effect of unparcelling Bundle
            /*
             * Filter messages based on message type. Since it is likely that
             * GCM will be extended in the future with new message types, just
             * ignore any message types you're not interested in, or that you
             * don't recognize.
             */
            if (GoogleCloudMessaging.MESSAGE_TYPE_SEND_ERROR.equals(messageType)) {
                sendPhoneActivityNotification("Send error: " + extras.toString(), "Error");
            } else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED.equals(messageType)) {
                sendPhoneActivityNotification("Deleted messages on server: " + extras.toString(), "Deleted");
                // If it's a regular GCM message, do some work.
            } else if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) {
                // Post notification of received message.
                String msg = extras.getString("message");
                PregnancyDataHandler pdh = new PregnancyDataHandler(getApplicationContext(), "fn received",
                        null, 1);
                Pregnancy preg = pdh.getPregnancy();

                if (TextUtils.isEmpty(msg)) {
                } else if (msg.contains("_R: ")) {
                    final String recommendationMessage = msg.replaceAll("_R: ", "");
                    Handler mHandler = new Handler(getMainLooper());
                    mHandler.post(new Runnable() {
                        @Override
                        public void run() {
                            RecommendationDataHandler rdh = new RecommendationDataHandler(
                                    getApplicationContext(), "Msg received", null, 1);
                            Calendar cal = Calendar.getInstance();
                            rdh.addRecommendation(recommendationMessage,
                                    Utils.getPregnancyDay(getApplicationContext()), cal.getTime(),
                                    Utils.getPregnancyWeek(getApplicationContext()));
                            sendNotification(getString(R.string.notification_text_new_recommendation),
                                    getString(R.string.app_name));
                        }
                    });
                } else if (msg.contains("_V: ")) {
                    final String visitMessage = msg.replaceAll("_V: ", "");
                    Handler mHandler = new Handler(getMainLooper());
                    mHandler.post(new Runnable() {
                        @Override
                        public void run() {
                            VisitDataHandler vdh = new VisitDataHandler(getApplicationContext(), "Msg received",
                                    null, 1);
                            vdh.addVisit(visitMessage);
                            sendNotification(getString(R.string.notification_text_new_visit),
                                    getString(R.string.app_name));
                        }
                    });
                } else if (msg.contains("_Verified")) {
                    Handler mHandler = new Handler(getMainLooper());
                    mHandler.post(new Runnable() {
                        @Override
                        public void run() {
                            PregnancyDataHandler pdh = new PregnancyDataHandler(getApplicationContext(),
                                    "Msg received", null, 1);
                            Toast.makeText(getApplicationContext(), getString(R.string.application_ready),
                                    Toast.LENGTH_LONG).show();
                            pdh.setVerified(true);
                            pdh.setLoadingProgress(pdh.getPregnancy().get_loadingProgress() + 1);
                        }
                    });
                } else if (msg.contains("_NotVerified")) {
                    Handler mHandler = new Handler(getMainLooper());
                    mHandler.post(new Runnable() {
                        @Override
                        public void run() {
                            PregnancyDataHandler pdh = new PregnancyDataHandler(getApplicationContext(),
                                    "not verified", null, 1);
                            pdh.setVerified(false);
                            Toast.makeText(getApplicationContext(), getString(R.string.number_not_verified),
                                    Toast.LENGTH_SHORT).show();
                        }
                    });
                } else if (msg.contains("_PregnancyNotFound")) {
                    Handler mHandler = new Handler(getMainLooper());
                    mHandler.post(new Runnable() {
                        @Override
                        public void run() {
                            PregnancyDataHandler pdh = new PregnancyDataHandler(getApplicationContext(),
                                    "Msg received", null, 1);
                            pdh.setVerified(false);
                            Toast.makeText(getApplicationContext(), getString(R.string.number_not_found),
                                    Toast.LENGTH_LONG).show();
                        }
                    });
                } else if (msg.contains("_PregnancyInfosFacilityName")) {
                    String pInfoFN = msg.replaceAll("_PregnancyInfosFacilityName: ", "");
                    pdh.updateFacilityName(pInfoFN);
                    pdh.setLoadingProgress(preg.get_loadingProgress() + 1);
                } else if (msg.contains("_PregnancyInfosFacilityPhone")) {
                    String pInfoFP = msg.replaceAll("_PregnancyInfosFacilityPhone: ", "");
                    pdh.updateFacilityPhone(pInfoFP);
                    pdh.setLoadingProgress(preg.get_loadingProgress() + 1);
                } else if (msg.contains("_PregnancyInfosExpectedDelivery")) {
                    String pInfoED = msg.replaceAll("_PregnancyInfosExpectedDelivery: ", "");
                    pdh.updateExpectedDelivery(pInfoED);
                    pdh.setLoadingProgress(preg.get_loadingProgress() + 1);
                } else if (msg.contains("_PregnancyInfosPatientName")) {
                    String pInfoPN = msg.replaceAll("_PregnancyInfosPatientName: ", "");
                    pdh.updatePatientName(pInfoPN);
                    pdh.setLoadingProgress(preg.get_loadingProgress() + 1);
                }

                Log.i("PregnancyGuide", "Received: " + extras.toString());
            }
        }
    } finally {
        // Release the wake lock provided by the WakefulBroadcastReceiver.
        GcmBroadcastReceiver.completeWakefulIntent(intent);
    }
}