Вопрос

I am trying to navigate back to a fragment of an activity from another activity. I have set

 getActionBar().setDisplayHomeAsUpEnabled(true);

but whenever, I use the app back icon it always takes me to the first fragment of the activity rather than the fragment from which another activity was launched. How can I achieve this. I think I might have to implement

getSupportFragmentManager().popBackStack();

How can I do it?

Это было полезно?

Решение

Try adding the fragment you want to go back to manually to the backstack.

FragmentTransaction transaction = getFragmentManager().beginTransaction();
YourFragmentName myFragment = new YourFragmentName();
transaction.replace(R.id.fragment_container, myFragment);

//if you with to add it to backStack, do this, otherwise skip the line below
transaction.addToBackStack(null);
transaction.commit();

Hope this helps.

Другие советы

hope no a late answer might help someone later you do this


FragmentManager fragmentManager = getFragmentManager();
fragmentManager.beginTransaction().replace(R.id.(the i of the layout of you current acticity),new (name of your activity)).commit();

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top