Android - Actions vs. Views

I am working on an Android application that has several screens that the user will have to navigate between them, and I am curious what is best used when switching between these screens. I am torn between creating a new action for each screen and just changing the view (setContentView (R.layout.whatever)). At least some variable values ​​are present on all screens, so I tend to change the views and use class-level variables, but I'm worried that one activity can become very large and confusing with the logic for several screens in one file. I want the code to be clean and separate, but I also don’t want to pass multiple variables between views if it is not required.

As a newbie to Android development, I hope some more experienced members of the community can share their thoughts and let me know how best to deal with this.

Thanks!

Note: I did not plan to use viewflipper. My thought was to use the button click event, and then call setContentView () on a new view for the page I wanted to open.

Example: my application starts using R.layout.main as it is viewed. The user clicks the Help button and calls the method that runs setContentView (R.layout.help); to display the help screen, as opposed to switching to help activity.

+7
android design
source share
2 answers

You should use the activity on the screen, as this makes the best use of the framework and allows the OS to selectively kill screens if the situation becomes dense.

If you have one activity and the resources become hard, the OS has two options; kill everything or kill nothing, and if the user does not use your application, then most likely he will kill everything.

If you use Activity behind the screen, the OS can kill some screens that the user has not visited for a while, while allowing others to remain active, allowing the user to quickly return to them.

Regarding the exchange of variables and values, you can use SQLite databases or SharedPreferences repositories to transfer them, if they are widespread, or use the putExtra methods in Intent if they are used only from one screen to another.

+9
source share

If you have variables that you will reuse, create a base class for them that you will extend.

It could be your user activity that extends the Activity .

As far as I can tell, you need to create separate actions for each view, only some situations can be handled by viewflippers.

0
source share

All Articles