luke2012 Well-Known Member Licensed User Longtime User Jul 20, 2020 #1 Hi all, I'm new to B4X and I'm starting a new cross-platform development (B4A & B4i). My question is: "which is the best way to share a sub between B4X components like B4XPages (https://bit.ly/3hgIPGp) from @Erel, Classes and modules ? My target is to implement a set of sub (like a little framework) that can be called from anywhere within the App (Android or iOS). Starter is the answer ? Thanks in advance for your precious help Luca.
Hi all, I'm new to B4X and I'm starting a new cross-platform development (B4A & B4i). My question is: "which is the best way to share a sub between B4X components like B4XPages (https://bit.ly/3hgIPGp) from @Erel, Classes and modules ? My target is to implement a set of sub (like a little framework) that can be called from anywhere within the App (Android or iOS). Starter is the answer ? Thanks in advance for your precious help Luca.
LucaMs Expert Licensed User Longtime User Jul 20, 2020 #2 luke2012 said: Starter is the answer ? Click to expand... Exists a Starter service in b4i? I don't think. I think you should create a class and an instance of if in the B4XMainPage. From the tutorial: There must be one class named B4XMainPage. This page will usually be the first one to be displayed. Upvote 0
luke2012 said: Starter is the answer ? Click to expand... Exists a Starter service in b4i? I don't think. I think you should create a class and an instance of if in the B4XMainPage. From the tutorial: There must be one class named B4XMainPage. This page will usually be the first one to be displayed.
LucaMs Expert Licensed User Longtime User Jul 20, 2020 #3 LucaMs said: Exists a Starter service in b4i? I don't think. I think you should create a class and an instance of if in the B4XMainPage. From the tutorial: There must be one class named B4XMainPage. This page will usually be the first one to be displayed. Click to expand... I'm "reading" the tutorial and found: 13. There is a field named B4XPages.B4XGlobalContext. The use case behind it is with a class instance that is initialized in Service_Create of the starter service. This can be a good place to implement tasks that can also run in the background. (there is a typo, its name is Globalcontext, without "B4X"). This also (?) could be the right place for your custom object. Upvote 0
LucaMs said: Exists a Starter service in b4i? I don't think. I think you should create a class and an instance of if in the B4XMainPage. From the tutorial: There must be one class named B4XMainPage. This page will usually be the first one to be displayed. Click to expand... I'm "reading" the tutorial and found: 13. There is a field named B4XPages.B4XGlobalContext. The use case behind it is with a class instance that is initialized in Service_Create of the starter service. This can be a good place to implement tasks that can also run in the background. (there is a typo, its name is Globalcontext, without "B4X"). This also (?) could be the right place for your custom object.
Sandman Expert Licensed User Longtime User Jul 20, 2020 #4 luke2012 said: Code: https://bit.ly/3hgIPGp Click to expand... Why would you ever want to link to a forum page using an url like that? Upvote 0
luke2012 said: Code: https://bit.ly/3hgIPGp Click to expand... Why would you ever want to link to a forum page using an url like that?
Alexander Stolte Expert Licensed User Longtime User Jul 20, 2020 #5 LucaMs said: Exists a Starter service in b4i? I don't think. Click to expand... But on B4I you can use it as a normal code module Upvote 0
LucaMs said: Exists a Starter service in b4i? I don't think. Click to expand... But on B4I you can use it as a normal code module
Erel B4X founder Staff member Licensed User Longtime User Jul 21, 2020 #6 Starter service is not the correct place for such code. Implement it in a class. Upvote 0
LucaMs Expert Licensed User Longtime User Jul 21, 2020 #7 Erel said: Starter service is not the correct place for such code. Implement it in a class. Click to expand... Yes, Erel, that's what I suggested in the first answer, but where to instantiate the class? In that answer I suggested, looking at your tutorial, in the B4XMainPage but then I noticed that this does not necessarily have to be the first to show: LucaMs said: This page will usually be the first one to be displayed. Click to expand... and that this "property" exists: LucaMs said: 13. There is a field named B4XPages.B4XGlobalContext. The use case behind it is with a class instance that is initialized in Service_Create of the starter service. This can be a good place to implement tasks that can also run in the background. Click to expand... which seems to be made just for this purpose. So where to instantiate a global class, an "utility singletone", which will certainly be instantiated "immediately" and accessible from anywhere? B4XMainPage or B4XPages.GlobalContext ("here" you cannot instantiate your class, you could only assign your object to it. After this last sentence of mine, I think the answer is obvious: B4XMainPage). Last edited: Jul 21, 2020 Upvote 0
Erel said: Starter service is not the correct place for such code. Implement it in a class. Click to expand... Yes, Erel, that's what I suggested in the first answer, but where to instantiate the class? In that answer I suggested, looking at your tutorial, in the B4XMainPage but then I noticed that this does not necessarily have to be the first to show: LucaMs said: This page will usually be the first one to be displayed. Click to expand... and that this "property" exists: LucaMs said: 13. There is a field named B4XPages.B4XGlobalContext. The use case behind it is with a class instance that is initialized in Service_Create of the starter service. This can be a good place to implement tasks that can also run in the background. Click to expand... which seems to be made just for this purpose. So where to instantiate a global class, an "utility singletone", which will certainly be instantiated "immediately" and accessible from anywhere? B4XMainPage or B4XPages.GlobalContext ("here" you cannot instantiate your class, you could only assign your object to it. After this last sentence of mine, I think the answer is obvious: B4XMainPage).
Erel B4X founder Staff member Licensed User Longtime User Jul 21, 2020 #8 LucaMs said: I noticed that this does not necessarily have to be the first to show: Click to expand... The only case where it will not be the first page to show is when the developer decides to show a different page in the Initialize sub of B4XMainPage. Still, B4XMainPage.Initialize will run before anything else (in B4XPages code). It only makes sense to use GlobalContext, if your app can start in the background, without showing anything. In that case B4XMainPage will not run at all. Upvote 0
LucaMs said: I noticed that this does not necessarily have to be the first to show: Click to expand... The only case where it will not be the first page to show is when the developer decides to show a different page in the Initialize sub of B4XMainPage. Still, B4XMainPage.Initialize will run before anything else (in B4XPages code). It only makes sense to use GlobalContext, if your app can start in the background, without showing anything. In that case B4XMainPage will not run at all.