FragmentActivity Back Stack on Back Button Pressed

1k views Asked by At

I am trying to implement fragments into an old app so I can support tablets. As I want to support pre 3.0 phones as well so I am using FragmentActivity from the v4 support package.

I have a main fragmentActivity which opens a second fragment activity if the app is not running on a tablet.

public class MainActivity extends FragmentActivity implements POIListFragment.ListItemSelectedListener{

    private POIDetailFragment detailFrag;
    private boolean isFirst = true;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.list_layout);

    }

    @Override
    public void onListItemSelected(String id, boolean isRest) {
        detailFrag = (POIDetailFragment) getSupportFragmentManager().findFragmentById(R.id.poiDetailFragment);

        if (detailFrag == null) {
            if(isFirst){
                isFirst = false;
            } else {
                Intent intent = new Intent(this, DetailFragmentActivity.class);
                Bundle data = new Bundle();
                data.putString("id", id);
                data.putBoolean("isRest", isRest);
                intent.putExtras(data);

                startActivity(intent);  
            }
        } else {
            detailFrag.update(id, isRest);
        }

}

This part of the code works fine. The statActivity(intent); opens the new fragmentactivity. However when the back button is pressed on that fragmentactivity the whole application closes.

How can I make the current fragmentactivity close revealing the previous one?

1

There are 1 answers

0
jiduvah On BEST ANSWER

Rookie error unfortunately. I had been previously using the activity as a splash screen and so had the android:noHistory="true" marks in the manifest. Its working fine after I changed that.