Android Question Timers in classes

davemorris

Active Member
Licensed User
Longtime User
Hi Guys
I have a question -

Firstly, I understand timers should be declared in an Activity's Sub Process_Globals - otherwise you get multiple timers when the activity is recreated (as discussed in B4A Core - Timer documentation).

If you declare a timer in a class, then it is declared in that Class's Sub Class_Globals (which I assume is correct).

When I create an Activity, I would normally declare that Class in the Activity's Sub Globals - But, if the Class includes timers, it appears that this Class MUST be declared in the Activity's Sub Process_Globals.

Is this correct or don't it matter for Classes with timers.

Kind regards
Dave
 

davemorris

Active Member
Licensed User
Longtime User
Hi Erel
Thanks the the quick response

Slight problem, it is old code so I don't want to change it to B4XPage at this point in time.
I do disable the timers when the activity is paused (otherwise the appear to retrigger when the activity is not shown which can cause all types of problems).

So (assuming B4XPages are currently out of the question at the moment) - should I declare these Classes (which include timers) in the Sub Process_Globals?

Regards
Dave
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
So (assuming B4XPages are currently out of the question at the moment) - should I declare these Classes (which include timers) in the Sub Process_Globals?
1. If you can declare it in Process_Globals then you probably should. This way the class instance will not be destroyed.
2. In many cases you can't because the class needs to have an activity context (you will see an error about it).
 
Upvote 0

davemorris

Active Member
Licensed User
Longtime User
Hi Erel
Thanks for the suggestions and help.

Guess I should take a look at converting to B4XPages to solve the problem - When I first looked at B4XPages you suggested not to jump it converting projects. However, on the forum over the past few months several successful attempts have been made. My project is B4X (developed for iOS and Android) approximately 15 Activities, 65 classes, 4 modules and 6 services.

Question (sorry if its a bit off topic) - Do you think I should attempt to convert now or wait a bit longer?

Regards

Dave
 
Upvote 0
Top