Android Studio activities question

  • Thread starter kolleamm
  • Start date
  • Tags
    Android
In summary, when creating apps, it is common practice to separate the code for the user interface (layout pages) from the code that performs actions. This allows for easier customization for different devices. It is recommended to have a top-level class with common properties and methods, and specialized classes for each page. However, if two pages are identical, there is no need for each page to have its own class.
  • #1
kolleamm
477
44
I noticed that when making apps there's activities which are the different classes and then there's the layout pages which are the different pages you see when using the app.

My question is, is the standard to create one class/activity that handles most of layout pages, or a class/activity for each layout page?
 
Technology news on Phys.org
  • #2
kolleamm said:
I noticed that when making apps there's activities which are the different classes and then there's the layout pages which are the different pages you see when using the app.

My question is, is the standard to create one class/activity that handles most of layout pages, or a class/activity for each layout page?
I'm not an Android programmer, so caveat emptor...

It's a common practice in programming in general to separate the code that presents the user interface (layout pages in your case) from the code that performs the actions. That way, the user interface can be customized for a variety of devices with different UIs without having to make changes to whatever actions need to be carried out.
 
  • Like
Likes sysprog
  • #3
Mark44 said:
I'm not an Android programmer, so caveat emptor...

It's a common practice in programming in general to separate the code that presents the user interface (layout pages in your case) from the code that performs the actions. That way, the user interface can be customized for a variety of devices with different UIs without having to make changes to whatever actions need to be carried out.
Hi you may have misunderstood what I mean. I wasn't referring to the code that generates the layout page. I was referring to whether each layout page should have its own class, or if there should be a single class that controls all the pages, function wise.
 
  • #4
kolleamm said:
Hi you may have misunderstood what I mean. I wasn't referring to the code that generates the layout page. I was referring to whether each layout page should have its own class, or if there should be a single class that controls all the pages, function wise.
A reasonable partition of things would be a top-level class that contains all of the properties and methods that are common to all pages, together with more specialized classes that would inherit from the top-level class. The specialized classes would take care of the differences between one page and another.

If two pages are identical, though, I don't see any reason for each page having its own class.
 
  • Like
Likes sysprog and kolleamm
  • #5
Mark44 said:
A reasonable partition of things would be a top-level class that contains all of the properties and methods that are common to all pages, together with more specialized classes that would inherit from the top-level class. The specialized classes would take care of the differences between one page and another.

If two pages are identical, though, I don't see any reason for each page having its own class.
Makes sense, I agree with the two page thing. Thanks!
 
  • Like
Likes sysprog

FAQ: Android Studio activities question

What is an activity in Android Studio?

An activity in Android Studio is a single screen or user interface that is designed to perform a specific task. It is a fundamental component of an Android application and serves as the entry point for user interaction.

How do you create an activity in Android Studio?

To create an activity in Android Studio, you can use the "New Activity" wizard by right-clicking on the package or folder where you want to create the activity. You can also create an activity by going to File > New > Activity.

What is the purpose of the onCreate() method in an activity?

The onCreate() method is a lifecycle method in an activity that is responsible for initializing the activity and setting up the user interface. It is called when the activity is first created and is where you should perform any initial setup for your activity.

How do you switch between activities in Android Studio?

To switch between activities in Android Studio, you can use the startActivity() method and pass in an Intent object that specifies the activity you want to switch to. You can also use the startActivityForResult() method if you want to receive a result from the activity you are switching to.

Can an activity be reused in different applications?

Yes, it is possible to reuse an activity in different applications. This can be done by creating a separate library project that contains the activity and then including it in the different applications. However, it is important to note that the activity may need to be modified to fit the specific functionality of each application.

Similar threads

Back
Top