Android Question Process globals, activities and main activities issue

bluedude

Well-Known Member
Licensed User
Longtime User
Hi all, (dropped the Erel part)

Before I start, i'm aware of the activity lifecycle etc. and have developed multiple B4A apps. However, currently i'm facing some problems with process-globals in a code module (which I always do).

Scenario
I'm running a multi activity app. which is bitmap intensive (caching etc.). In my Main activity by using Firsttime I load and assign some process_globals variables from a code module. In here I also prepare key value storage (SQL). My other activities also update process_global variables.

What happens
After a switching a few times between apps. I noticed my activities get recreated (which is normal) but I lose values from the process_globals in my code module.

In the list of apps. running (Nexus 5, on screen button right) I notice my current activity still shows.

When clicking on the app. in the list it recreates the activity but my process_globals have lost their values. Actually, it also lost stuff like initializing key value store etc.

Unclear???
When process_globals have lost their values does that mean the Process is not there anymore? If that is the case why is my app. still showing in the list of apps.?

If the process is killed does that always mean my Main activity starts when clicking the app. in the list of apps.? My Main actually does not start again when clicking in the list of apps., it only recreates the current activity so that would assume the process is still there.

I'm 100% sure that I don't clear the process_globals variables myself. To test this I now also initialize some values in every activity Create (by using Firsttime keyword) and then all works. However, I notices when I move back to my main screen it kicks off Firsttime again.

How do I exactly know when the process is killed and process_globals are empty?
 
Last edited:

Erel

B4X founder
Staff member
Licensed User
Longtime User
This is a community forum. Please don't limit your questions to a single member...

The list of recent apps shows the recent apps. It doesn't show the current active processes.
Your app can start from a different activity in some cases.
The best solution is to create an initialize method in one of the code modules that takes care of initializing the process global objects if needed. You can then call this method from all the activities.

Another option is to check whether the object is initialized or not. If not start the main activity and finish the current one.
 
Upvote 0

RandomCoder

Well-Known Member
Licensed User
Longtime User
Hi bluedude, I realise you probably know more about programming Android than me, but it does sound like the process is being killed presumably so that the OS can free up more resources for the currently running process. Not sure why it's not being removed from the list of running apps though, but as it's triggering the firsttime bool them it must be.
How much work would it be to transfer the globals across to a service module which you could then attempt to keep running?

Regards,
RandomCoder
 
Upvote 0

bluedude

Well-Known Member
Licensed User
Longtime User
Hi,

Basically I do this right now (initialize global procedure in all activities) but i'm wondering why Main does not start automatically if process globals seems to be empty? I assume that would mean process is ended.

Slightly worried about memory if I do these checks but I guess Android has already killed and emptied the memory for me when the activity gets created again
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…