Question: How can I launch a new Activity to a Fragment that is not the initial fragment? For example, the following code is wrong. I want to launch the MainActivity.class AT the SecondFragment.class. Seems simple enough but cannot find an answer anywhere. All help is greatly appreciated!

```
public void LaunchSecondFragment(View view) {
    view.startAnimation(AnimationUtils.loadAnimation(this, R.anim.image_click));

    Intent intent = new Intent(this, SecondFragment.class);
    startActivity(intent);
}

```

Answer: 
Try this to start the activity:

```
Intent intent = new Intent(this, MainActivity.class);   
int fragmentIndex = 2;
intent.putExtra("fragment_index", fragmentIndex);
startActivity(intent);

```

and this for the MainActivity's onCreate

```
Bundle extras = getIntent().getExtras();
int fragmentIndex;
if(extras != null) {
    fragmentIndex = extras.getInt("fragment_index",1);
}
switch(fragmentIndex) {
    case 1:
        //display fragment 1
        break;
    case 2:
        //display fragment 2
        break;
    case 3:
        //display fragment 3
        break;
}

```
When user clicks button and your `MainActivity` opens, its `onCreate()` will be get called. 

You should add fragment transaction in `onCreate()` to launch `SecondFragment` :

```
FragmentTransaction ft = getFragmentManager().beginTransaction();
SecondFragment secondFragment = new SecondFragment();
ft.replace(R.id.content_frame, secondFragment);
ft.commitAllowingStateLoss();

```