Android Question Add dynamically modules & copy Modules

Erind Jushaj

Member
Licensed User
Is there a way to add new modules by code?
I have an app where first I have to fill in a few editboxes but I would like for them to be saved as a template module. So i thought to write a code which copies the active module and stores it as a new module which I could call later.

Is this possible and is it possible to save them so that I can call them after I reopen my app later?

Many thanks
 

Erind Jushaj

Member
Licensed User
I'm not clear on what it is you're trying to accomplish, but perhaps this link may be of use?
https://www.b4x.com/android/forum/t...applications-settings-and-state.9777/#content

I have an app where I have manually added a module which I can call from Main.
THis module contains a few empty text boxes whic I can fill in.
Now I would like to have a button on the app that allowes me to make a copy of this module and save it with a different name (kind of a pre filled template)..
 
Upvote 0

Jeffrey Cameron

Well-Known Member
Licensed User
Longtime User
By "module" you mean "Activity?" If so, please see the link I posted earlier. I think you can accomplish what you wish by using @Erel's StateManager and giving different key names (e.g. ".SaveState(Activity, "Module-Copy1") for your different templates.
 
Upvote 0

Erind Jushaj

Member
Licensed User
Yes sorry I meant Activity. And the thread you sent me to enables me to save the state which is perfect.
Now I just would like to know if there is a code which I can set on a button to save a copy ot the current activity under another name? and permanently have it added as a template.

Quick example:
Main activity contains 2 editboxes. Editbox1.text= Name1, Editbox2.text = Age1

I want to save the main activity as a new activity being called "First Person" and reset the main activity editbox1.text = "" en editbox2.text=""

Next time I open the program i want to have the Main activity with the blanco editboxes but want to be able to call Activity "First Person".

And so I want to be able to add many times different Activities..
 
Upvote 0

Jeffrey Cameron

Well-Known Member
Licensed User
Longtime User
If they choose to save the "template" use the statemanager with a different key name, for example
B4X:
Sub Activity_Create(FirstTime As Boolean)
    'Load the previous state
    If StateManager.RestoreState(Activity, "Main", 60) = False Then
        'set the default values
        EditText1.Text = "Default text"
        EditText2.Text = "Default text"
    End If
End Sub

Sub Activity_Pause (UserClosed As Boolean)
    If UserClosed Then
        StateManager.ResetState("Main")
    Else
        StateManager.SaveState(Activity, "Main")
    End If
    StateManager.SaveSettings
End Sub

Sub SaveTemplateButton_Click
    StateManager.SaveState(Activity, "Main-Template1")
End Sub

Sub LoadTemplateButton_Click
    If StateManager.RestoreState(Activity, "Main-Template1", 0) = False Then
        ' show error toast of some kind or ignore
    End If
End Sub
 
Upvote 0

Jeffrey Cameron

Well-Known Member
Licensed User
Longtime User
Again, I'm not sure exactly what the purpose of your UI is to achieve, but it seems to me this would be better suited for just one state manger and some type of database to record/retrieve the entries when they need to be repopulated.

Just my two cents
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…