Answer the question
In order to leave comments, you need to log in
In which cases is it better to use fragments, and in which activities?
I have a google map app. The user is given the opportunity to search for objects, respectively, they are displayed on the map and there are filters, a list of results and a view of a separate result.
Now in the already written application, this is one activity, inside of which there is a map, and on top of it there are a number of fragments - with filters, a list of objects and a view of a separate object. All these fragments are full-screen, that is, they obscure the entire parent activity.
In view of the problems with the backstack, I thought if I did the right thing, perhaps these fragments should be full-fledged activities?
Although there I see the problem of communications and data transfer between different activities, while now I can safely use the necessary fragment methods from the parent activity.
And the second question - are there any good articles about the architecture of android applications?
Upd: it seems that when using activation - switching occurs more slowly.
upd2:
More: there is a main screen (activities) with a map, on top of the input field (a separate fragment), a counter of meters and time (a separate fragment), a couple of buttons.
There are additional screens that cover the entire parent screen and they are designed in the form of fragments:
selection of filters, list of objects, information about one object.
The question concerns the last three, although judging by the fact that they look like separate screens, they probably should be exactly the activity. But then it is not very convenient to transfer information back and forth (for example, information about which filters are selected to transfer to an activity with a map where the search takes place)
Answer the question
In order to leave comments, you need to log in
If there is a requirement to completely close the parent screen, then it is worth considering that this is, in fact, a separate screen. The only legitimate case where you can close parts of the parent screen is in a dialog.
It's really not always convenient to transfer data between the application's Activity. However, supporting this kind of communication between screens will allow you, for example, to open the map screen from a completely different place (for example, Push notifications, or even another application) using the same protocol, Extras in Intent. This is the principle of organizing an Android application. Loosely coupled application screens. In order to go to some screen specifically in order to return data from there, there is a startActivityForResult mechanism.
по своему опыту, использую фрагменты только в виде DialogFragment. Все.
На счет передачи данных между активити - Parcelable чрезвычайно удобен. Либо класс сериализовать в жсон. Либо перегнать его в byte[]->Base64 строка->передать ч/з интент->Base64>new String();
Да и некий bus для app-wide notifications нужен для любого мало мальски большого приложения... через него тоже можно данные гонять.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question