Android Question Share Class between activities.

TheGiant

Member
Licensed User
Longtime User
Hello,

I am a newbie with Basic4Android i am trying the following:

I have a Game class which holds the game info:
B4X:
Type=Class
Version=3
@EndOfDesignText@

'Class module
Sub Class_Globals
    CurrentPlayer as Player
End Sub

'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize
    'LoadPlayersFromDatabase
End Sub

Public Sub TestMe
    Msgbox("","TestMe")
End Sub

Then i have main from which loads the class the the players form
B4X:
Sub Process_Globals
    Public Game As clsGame
    Game.Initialize
End Sub

Sub Globals
    Dim pnlBottom As Panel
    Dim pnlTop As Panel
    Dim btnStart As Button
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("frmmain")
End Sub

Sub btnStart_Click
    StartActivity(frmPlayers)
End Sub

But if i call frmPlayers the class i don't see the Msgbox

B4X:
Sub Globals
    Dim btnStart As Button
    Dim lstPlayers As ListView
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("frmplayers")
End Sub

Sub btnStart_Click
    Main.Game.TestMe
End Sub

I only want to load the players once and 'share' the Main.Game between activities.

I hope i makes sense.

Thanks in advance.
 

TheGiant

Member
Licensed User
Longtime User
Thanks!
Where can i find the Log message when i use the trail version?
I know there is a Log tabbar but the Log messages will not show there.:(
 
Upvote 0

TheGiant

Member
Licensed User
Longtime User
Hello everything works fine now!
Except when the application is resumed i get the error
game_activity_resume (java line:320) java.lang.NullPointerException.
What can i do?
 
Upvote 0
Top