A
A
AlexCodly2014-10-02 12:06:08
Android
AlexCodly, 2014-10-02 12:06:08

Activity or fragment (android)?

There is such a question. Once I played with fragments and wanted to do this: there is an activity, there is a fragment in it, we press the button in the fragment and this fragment is replaced with a new one. But errors flew out and I realized by googling that this is impossible.
But recently I looked at how Telegram and WhatsApp work. What I was talking about was implemented in Telegram (either the activity does not appear there as standard, or everything is displayed there without layouts, immediately programmatically and when you click on the interlocutor, it is programmatically replaced). Whereas in Watsap everything is simple.
Please explain to me how they did it and what are the differences.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
C
Copperfield, 2014-10-02
@AlexCodly

FragmentManager fragmentManager = getActivity().getFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
ExampleFragment fragment = new ExampleFragment();
fragmentTransaction.add(R.id.fragment_container, fragment);
fragmentTransaction.commit();

Q
questman, 2014-10-09
@questman

The source code of the Telegram Android application is on github. So you can safely explore it.
In a nutshell: they don’t have activities at all, but their own parody of them with the help of fragments and one activity.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question