Is it recommended to use more than one Activity in an Android project?

Asked

Viewed 374 times

0

I always use several (in large project with web service and everything), the ideal is to use only one or no problems use several?

  • 2

    I don’t understand what problem made you question the use of several activities. After all, one Activity is a component that provides a screen for user interaction, that is, in a whole application it is likely that there are several.

  • 1

    What is recommended is that a Activity focus on a single subject/activity.

  • It is possible to have an application with a Activity and several Fragments, and this can bring you advantages compared to the approach with several Activities.

4 answers

1

Use more than one Activity is an option and not an obligation; with the advent of Fragments, you can have an app with a single Activity and several Fragments, that would effectively be the screens of your application.

As I once heard, the Activity would be the stage and the Fragments the actors.

An application like this behaves like a SPA (Single Page Application).

Perks:

  • Support for tablet-specific layouts;
  • AsyncTasks do not depend on the obsolete method onRetainNonConfigurationInstance() (or of worse thing) so that they are not destroyed during a screen rotation or any other configuration change;
  • To Action Bar is not recreated with each screen change.

0

Yes, normally each Activity dams an Android project screen.

0

You can use as many Activity as is necessary for your needs, what happens is that very large multi-screen projects require more organization and process control.

0

Better use an Activity for each screen. If you use methods to inflate another layout, you will be carrying the baggage of the previous layout, such as open database, visible keyboard, etc. It is good practice an Activity for each Layout.

Browser other questions tagged

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