Android Studio activities question

  • Thread starter Thread starter kolleamm
  • Start date Start date
  • Tags Tags
    Android
Click For Summary
In Android app development, it's common to separate user interface code from action code for flexibility across devices. The discussion revolves around whether to use a single class for multiple layout pages or to create individual classes for each layout. A recommended approach is to have a top-level class that contains shared properties and methods, with specialized subclasses for unique pages. If two pages are identical, there's no need for separate classes. This structure enhances code organization and maintainability.
kolleamm
Messages
476
Reaction score
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
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
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.
 
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
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
I tried a web search "the loss of programming ", and found an article saying that all aspects of writing, developing, and testing software programs will one day all be handled through artificial intelligence. One must wonder then, who is responsible. WHO is responsible for any problems, bugs, deficiencies, or whatever malfunctions which the programs make their users endure? Things may work wrong however the "wrong" happens. AI needs to fix the problems for the users. Any way to...

Similar threads

Replies
11
Views
3K
  • · Replies 10 ·
Replies
10
Views
2K
  • · Replies 1 ·
Replies
1
Views
4K
Replies
3
Views
1K
Replies
4
Views
3K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 50 ·
2
Replies
50
Views
8K
  • · Replies 5 ·
Replies
5
Views
3K