How not to use so many activities?

Asked

Viewed 87 times

2

Hello, I’m starting to program something on android a few days ago (a very simple but extensive shell identification program, in it you have 5 options, within these 5 more some depending on the species, and within more options until you reach a specific shell with all the information from it), so I was creating layouts and activities for each species, class, etc... ended up giving about 200 layouts and activities and I still haven’t reached the end of the kkkk program and only then I thought "there’s something wrong with that" hehe. So I wonder if there is any other way to make a program of this type with options within options, totally offline, without using so many activities and layouts.

  • 1

    You can use custom... dialogs... dialogs... not necessarily always activities... the way of Cvoce to adapt the code that will say... if each option opens a page for example and Voce quizer only one Activity Voce creates dialogs... each opens a "screen" different but in reality only has 1...

  • The solution is to use Fragments, in the limit, an Activity may be sufficient for the entire application. https://developer.android.com/training/basics/fragments/index.html The layouts can be re-used, while the logic may have to be rewritten.

1 answer

1


Dude, if I mean right, you have a catalog with multiple shells, and you want to display them on a list where the user can select one and see the details, right? If yes, you are going the wrong way by making an Activity/Ragment for each shell, think to me if Oce has a "Shell" object, you could not make a Fragment for the listing and one for the detail? This detail Fragment would be generic and would display the information of a shell object. Correct me if I don’t mean your idea, but if the idea is this: "Display shell list and details" then you’re in the wrong direction, if the idea is: "For each shell I want to create a certain logic different for example species X does a certain action, species Y does a completely different action than X" ai sim Voce should create a Fragment for each species. And if you do not know how to store these shells that is not fixed in a Ragment gives a study on the Android database. NO HARD CODE!

  • That’s about it, only they’re options within options. For example, for Gastropoda I have 3 options Marine, Terrestrial and Fresh Water, inside Terrestrial I have 19 more options that are families, inside Marine I have 102 options, And in Agua Doce 8 kkkk and to top it off I have an average of 5 species per family totaling about 500 species in Gastropodas kkkk Would there be a way to make it all offline? or it would be a really great app?

  • If you need a tree hierarchy structure, you can use a noSQL database, or save a JSON with this information. I advise creating an application to update the database (or JSON), if not you will go crazy when updating the information. It has to do in relational bank as well, but then it leaves the scope of the question.

  • Yes Vanjura, you have there a modeling error, you do not need to create an Activity or Fragment for each of the 500 species of Gastropodas, and yes, you can keep this up in a relational database that is the case of Sqlite that android uses, of course this generates a little more work than if you use the SQL database as Daniel suggested, but from what I see you are starting in development, so to simplify you could use the relational database (SQL) and rethink your modeling

  • rethinking the modeling would be like: A shell is an entity, what attributes do all of them (the shells in general) have? any have any specific attribute(Only this one has this attribute)? I need to make an inheritance? for example: parent class: Shell, daughter class: Gastropodas, got it? if you do so you will probably end up with 1 Activity and a small portion of Fragments that could be used generically for all over 500 species of shells and still break will have a more elegant and easy to maintain code :)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.