Android Question Initialize class during runtime

aaronk

Well-Known Member
Licensed User
Longtime User
Hi,

Just wondering how I can initialize a class during runtime?

I have created a class and I have used it in a service, but during runtime I want to be able to initialize it many times.

I know how to initialize it (MyClass.initialize) but can't work out how to initialize it multiple times.

For example:
When I open the app I want to press a button and it will initialize the class.

eg. MyClass.initialize("test1")

I then want to press the same button again, but initialize it with a different string
eg. MyClass.initialize("test2")

I want to be able to initialize the class multiple times without closing the previous one.
I am guessing I need to Dim it in the Process_Globals ad then initialize it in Service_Create but can't work out how to do it multiple times during runtime.

Anyone able to help me out ?
 

aaronk

Well-Known Member
Licensed User
Longtime User
Do you want to create multiple instances of this class?

If yes then you need to call Dim varName As YourClass and then initialize the new object.
Just like what Klaus suggested?

If so, that will be pain as I wanted to keep pressing a button to add them without having to dim each of them since I might not know how many there are going to be.

Would you say something like this will work?

B4X:
Dim MyNewClass(1000) As MyClass
      MyNewClass(1).Initialite("table1")

Then each time I press a button add one: MyNewClass(2).Initialite("table2)
 
Upvote 0
Top