title: How can I launch a fragment from a Broadcast Receiver?
body: <p>How can I launch my a particular fragment within an activity from my Parse Broadcast Receiver? When a user receives a notification I want them to open immediately to Fragment B of Activity A, for example. Is this possible? I feel like I should be able to force a fragment change from Activity A in its onCreate method using an intent extra...</p>
  
  <pre><code>public class Receiver extends ParsePushBroadcastReceiver {
  
      @Override
      protected Bitmap getLargeIcon(Context context, Intent intent) {
          return BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_launcher);
      }
  
      @Override
      protected void onPushOpen(Context context, Intent intent) {
  
          ParseAnalytics.trackAppOpenedInBackground(intent);
  
          String uriString = null;
          try {
              JSONObject pushData = new JSONObject(intent.getStringExtra("com.parse.Data"));
              uriString = pushData.optString("uri");
          } catch (JSONException e) {
              Log.v(getClass().toString(), "Unexpected JSONException when receiving push data: ", e);
          }
          Class&lt;? extends Activity&gt; cls = getActivity(context, intent);
          Intent activityIntent;
          if (uriString != null &amp;&amp; !uriString.isEmpty()) {
              activityIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(uriString));
          } else {
              activityIntent = new Intent(context, MainActivity.class);
              activityIntent.putExtra("fragment", "fragment2");
              activityIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
              context.startActivity(activityIntent);
          }
          activityIntent.putExtras(intent.getExtras());
          if (Build.VERSION.SDK_INT &gt;= 16) {
              TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
              stackBuilder.addParentStack(cls);
              stackBuilder.addNextIntent(activityIntent);
              stackBuilder.startActivities();
          } else {
              activityIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
              activityIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
              context.startActivity(activityIntent);
          }
  
      }
  }
  </code></pre>
  
  <p><strong>MainActivity (Activity A)</strong></p>
  
  <p>In my onCreate I put the following:</p>
  
  <pre><code>Bundle bundle = getIntent().getExtras();
          if (bundle != null) {
              if (bundle.getString("fragment") != null) {
                  /*Log.w(getClass().toString(), bundle.getString("fragment"));*/
                  viewPager.setCurrentItem(1);
              }
          }
  </code></pre>
  
  <p>Unfortunately it doesn't automatically move to Fragment B.</p>