I stripped down my app. The code is below.
I first run with Main, Starter(empty), actTestClass and TestClass in the project, without AddApplicationText(<activity android:name="b4a.testclass.TestClass"/>) in the manifest.
The activity shows up with the textbox loaded with the number; clicking the button closes the activity, and the Toast shows the number. Just as intended.
I compile the library, remove the testClass and actTestClass, restart the project, and load the Library.
When I run it with or without using the library, with or without AddApplicationText(<activity android:name="b4a.testclass.TestClass"/>) n the Manifest I get the error
actTestClass:Activity_Create
java.lang.RuntimeException: Object should first be initialized (Activity).
Thanks in advance!
This is Main
#Region Project Attributes
#ApplicationLabel: B4A TestClass
#VersionCode: 1
#VersionName:
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: False
#LibraryName: TestClass
#LibraryAuthor: Steve Wheaton
#LibraryVersion:1.0
#End Region
#Region Activity Attributes
#FullScreen: False
#IncludeTitle: True
#End Region
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Private btnStart As Button
Dim cTest As TestClass
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("main")
cTest.Initialize(Me,cTest)
cTest.ID = 12
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub btnStart_Click
cTest.LoadItems
End Sub
Public Sub ClassResult(ID As Long)
ToastMessageShow(ID, False)
End Sub
This is the Class TestClass
'Class TestClass
'ver 1.0
'Sept 5/18
Sub Class_Globals
Private mCallback, myobj As Object
Private mID As Long
End Sub
'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize(CallBack As Object,MyObject As TestClass)
Log("TestClass:Initialize")
mCallback = CallBack
myobj = MyObject
End Sub
Public Sub LoadItems
Log("TestClass:LoadItems")
CallSubDelayed2(actTestClass,"StartAct",myobj)
Sleep(0)
End Sub
Public Sub Result(ID As Long)
Log("TestClass:Result")
mID = ID
CallSubDelayed2(mCallback,"ClassResult",mID)
End Sub
Public Sub setID (val As Long)
mID = val
End Sub
Public Sub getID As Long
Return mID
End Sub
This is the Activity actTestClass
#Region Activity Attributes
#FullScreen: False
#IncludeTitle: True
#ExcludeFromLibrary: False
#End Region
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Private mCallback As TestClass
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Private btnQuit As Button
Dim pnlDisplay As Panel
Private mNumber As Long
Private EditText1 As EditText
Private butQuit As Button
End Sub
Sub Activity_Create(FirstTime As Boolean)
Log("actTestClass:Activity_Create")
'Do not forget to load the layout file created with the visual designer. For example:
Activity.LoadLayout("frmTestClass")
pnlDisplay.Initialize("")
pnlDisplay.Color =Colors.White
pnlDisplay.Visible = True
'Activity.AddView(pnlDisplay,0,40%y,100%x,60%y)
Activity.AddView(pnlDisplay,20dip,400dip,50%x,50%y)
End Sub
Public Sub StartAct(Callback As TestClass)'
Log("actTestClass:StartAct")
mCallback = Callback
LoadItems
End Sub
Sub LoadItems
Log("actTestClass:LoadItems")
'Activity.Title = "Add Item: " & RoomName
Dim b As Boolean
mNumber = mCallback.ID
EditText1.Text = mNumber
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub butQuit_Click
Log("actTextClass:btnQuit")
CallSub2(mCallback,"Result",mNumber)
Activity.Finish
End Sub
This is the Manifest
'This code will be applied to the manifest file during compilation.
'You do not need to modify it in most cases.
'See this link for for more information: https://www.b4x.com/forum/showthread.php?p=78136
AddManifestText(
<uses-sdk android:minSdkVersion="5" android:targetSdkVersion="26"/>
<supports-screens android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"
android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
CreateResourceFromFile(Macro, Themes.DarkTheme)
'End of default text.
AddApplicationText(<activity android:name="b4a.testclass.TestClass"/>)