Martin Larsen Active Member Licensed User Longtime User Sep 26, 2019 #1 I am starting on a B4A - B4i cross platform project and I want to use XUI for this. I have a few questions, though. It is recommended in the video tutorials to move most of the code from the activity to a shared class module. But for multiple activities, should I use a new class module for each activity or use the same class module for all? Is there a best-practice for naming the corresponding class modules? For example, with a prefix. For now, I have prefixed the class modules with xui. So Main is handled by xuiMain etc. How do I finish an activity from the xui class module? Right now I have a sub in the activity and call it with CallSub, eg. Code: Copy CallSub(Splash, "Finish") Is there a way to finish the activity directly?
I am starting on a B4A - B4i cross platform project and I want to use XUI for this. I have a few questions, though. It is recommended in the video tutorials to move most of the code from the activity to a shared class module. But for multiple activities, should I use a new class module for each activity or use the same class module for all? Is there a best-practice for naming the corresponding class modules? For example, with a prefix. For now, I have prefixed the class modules with xui. So Main is handled by xuiMain etc. How do I finish an activity from the xui class module? Right now I have a sub in the activity and call it with CallSub, eg. Code: Copy CallSub(Splash, "Finish") Is there a way to finish the activity directly?
Erel B4X founder Staff member Licensed User Longtime User Sep 26, 2019 #2 Martin Larsen said: It is recommended in the video tutorials to move most of the code from the activity to a shared class module. But for multiple activities, should I use a new class module for each activity or use the same class module for all? Click to expand... It depends. If it makes sense to reuse the "component" in multiple activities then reuse the class. If not then create multiple classes. You can also use multiple classes in the same activity. For example the drawer can be implemented in a class and reused in all activities and other stuff can be implemented in other classes. Martin Larsen said: Is there a way to finish the activity directly? Click to expand... Not really. The only thing that I can add is that you can pass the "callback" object and use it instead of hard coding the activity name (relevant if the class can be reused with other activities). Upvote 0
Martin Larsen said: It is recommended in the video tutorials to move most of the code from the activity to a shared class module. But for multiple activities, should I use a new class module for each activity or use the same class module for all? Click to expand... It depends. If it makes sense to reuse the "component" in multiple activities then reuse the class. If not then create multiple classes. You can also use multiple classes in the same activity. For example the drawer can be implemented in a class and reused in all activities and other stuff can be implemented in other classes. Martin Larsen said: Is there a way to finish the activity directly? Click to expand... Not really. The only thing that I can add is that you can pass the "callback" object and use it instead of hard coding the activity name (relevant if the class can be reused with other activities).
Martin Larsen Active Member Licensed User Longtime User Sep 27, 2019 #3 Erel said: he only thing that I can add is that you can pass the "callback" object Click to expand... What callback object? Do you mean the Parent parameter passed to Sub Initialize in the the class module? Code: Copy Public Sub Initialize(Parent As B4XView) Parent.LoadLayout("1") End Sub Upvote 0
Erel said: he only thing that I can add is that you can pass the "callback" object Click to expand... What callback object? Do you mean the Parent parameter passed to Sub Initialize in the the class module? Code: Copy Public Sub Initialize(Parent As B4XView) Parent.LoadLayout("1") End Sub
DonManfred Expert Licensed User Longtime User Sep 27, 2019 #4 Martin Larsen said: What callback object? Click to expand... Watch it completely. Watch out more carefully begining at minute 13 of the Video. Upvote 0
Martin Larsen said: What callback object? Click to expand... Watch it completely. Watch out more carefully begining at minute 13 of the Video.