Android Question Best Practice: multiple activities vs. multiple panels

DaveW

Active Member
Licensed User
Longtime User
As a beginner (coming from Delphi) and would like to get off on the right foot with my first B4A app. It seems to me that the first major decision to be made is whether to have a single activity with multiple panels for the layouts or have one activity for each layout. Reading through the forum postings, tutorials and guides I see a lot about how to implement the 2 methods but not a lot about why to use one or the other. I can see a few superficial reasons for choosing one or the other but are there deeper, less obvious factors that I should consider?

On the surface, the main difference I notice is the division of code. If multiple activities are used each activity only needs to contain the code for one layout. I think this would be much easier to manage when coding.

However multiple activities means you must have your data much better organised to ensure the bits you need are available between layouts (not a bad thing but more work that I am used to coming from Delphi!)

Creating and switching between multiple panels in one activity also seems to involve a lot of tedious code (creating the holder-panels, loading the layouts, hiding all the unused panels when a switch is made). I get the feeling this is unnecessary (or simpler) when using multiple activities.

Do any of the many B4A experts out there have any opinions on this matter?
 

DaveW

Active Member
Licensed User
Longtime User
Thank you NJ for the reply, however it does not really answer my question. You say multiple activities are recommended - but I have not seen that stated anywhere. Can you refer me to something that says this? I am certainly not disagreeing with you, it's just that both methods are described and supported in B4A and I would like to know why I should use one or the other.

David.
 
Upvote 0

sorex

Expert
Licensed User
Longtime User
I used multiple panels in a few projects.

Due to the large chunks of code I tried to use activities aswell to get code splitted.

I dropped the activities idea since moving between them seems to be slow or has some side effects (like these zoom in/out effects which I don't like)

If you like the panels method you can still split the code up into several classes or code modules, notice that these might behave weird since their logic/scope is kind of different.

The only problem left then is the layout designer with all these panels in it, not sure if it is possible to work around that.
 
Upvote 0

ac9ts

Active Member
Licensed User
Longtime User
Another thing to think of is screen size. I wrote an app that when run on a phone (small screen), it had multiple screens/activities. When it was run on a tablet, some of the activities were combined on the main screen and some of the others were combined onto a second screen. As far as the code went, the various view callbacks called into a code or service module. In some instances, it was easier to have the same function in each activity module rather than a call to another module.
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
I recommend using separate activities, thats the way Android was designed for. It's much easier to manage the code.

But it can depend on the kind of application you want to write.

If you want to use Tabs or sliding panels then you will have different panels in the same activity (StdActionBar library).
You could also have a combination of both using activities and inside some activities using Tabs or sliding panels.
I haven't yet used StdActionBar but many recent applications use it.

In one application which runs on smartphones and tablets I use one activity with eight panels.
The reason is that I wanted only one source code file for both screen sizes.
On small screens the applicaion works in portrait mode only and the panels cover the whole screen.
On the big screens it works only in landscape mode and I display two panels side by side at the same time, a 'main' panel at the left side and complementary panels on the right side.
 
Upvote 0

DaveW

Active Member
Licensed User
Longtime User
Thank you all for your comments. As is so often the case, the basic answer seems to be "it depends"! o_O
I think I will just have to try both and see which works out best as the program evolves

David.
 
Upvote 0
Top