Android Question Garbage collecting and class loading question

SeaBee

Member
Licensed User
I have been writing Windows form apps using MS Visual Studio since version 1, so am very familiar with MS garbage collection and the JIT compiler. However, I have only been writing for Android since last year, and don't know how it works.

The plan is for a single app with four disparate Activities. These Activities are totally separate in functionality, but are bound together only by a single technical discipline. At present, what I have are the four activities (small A) each in its own app, as I found it easier to write this way, concentrating on just one at a time. Now I must merge these four components into a single app with a menu to select them. Each current component will become an Activity using the name of the current app, with Main just holding the menu and other essential stuff. Each current app has just the UI stuff in Main, passing the user input to various modules and classes, and collecting the output for formatting and display. Altogether, it will be a big app, so my questions:-

1. Does Android load all the app classes and modules at start, or are they only loaded when the Activity is started?

2. Is it possible to preserve the state of one Activity when another is started, and is it possible to give the user the option to save state or not?

3. Am I crazy to build a highly complex app this way in the first place? :D

Thanks for any explanation,

Chris C-B
 
Last edited:

Ricky D

Well-Known Member
Licensed User
Longtime User
I have been writing Windows form apps using MS Visual Studio since version 1, so am very familiar with MS garbage collection and the JIT compiler. However, I have only been writing for Android since last year, and don't know how it works.

The plan is for a single app with four disparate Activities. These Activities are totally separate in functionality, but are bound together only by a single technical discipline. At present, what I have are the four activities (small A) each in its own app, as I found it easier to write this way, concentrating on just one at a time. Now I must merge these four components into a single app with a menu to select them. Each current component will become an Activity using the name of the current app, with Main just holding the menu and other essential stuff. Each current app has just the UI stuff in Main, passing the user input to various modules and classes, and collecting the output for formatting and display. Altogether, it will be a big app, so my questions:-

1. Does Android load all the app classes and modules at start, or are they only loaded when the Activity is started?

2. Is it possible to preserve the state of one Activity when another is started, and is it possible to give the user the option to save state or not?

3. Am I crazy to build a highly complex app this way in the first place? :D

Thanks for any explanation,

Chris C-B
I'd give them a msgbox to decide if they want the state saved
 
Upvote 0

SeaBee

Member
Licensed User
1. Classes are never loaded. Only class instances are loaded. They are loaded whenever you create a new instance.
The same is true for activities. They will only be loaded when the activity is started.
Thanks for this. How about standard code modules - can they be associated with a specific Activity, so do not load with the Main Activity when the particular sub-Activity does not use them?

2. Check StateManager. It is a module that helps with preserving the activity UI state.
Again, thanks - saves a lot of work!

Chris C-B
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Thanks for this. How about standard code modules - can they be associated with a specific Activity, so do not load with the Main Activity when the particular sub-Activity does not use them?
You don't need to be worried about the memory usage of modules. Your program will not run out of available memory even if you add 1,000,000 modules.

The memory required depends on the process global variables.
 
Upvote 0

SeaBee

Member
Licensed User
Thanks again. There will be very few Process_Globals as just about everything will be in Globals for each Activity or Dims in a Sub.

Absolutely first class support from this site - thanks.
 
Upvote 0
Top