Hi all.
i m working to make a startapp lib on B4A and now i have a problem..
the code below is working perfectly in an activity, however when I try to use it in a class it does not start correctly.
I intend to compile it as a library, to use in other projects.
Instead of using
How can I get the activity in which the class was started?
For example in main I started with the following command.
However, ctxt.InitializeContext is initialized with class and not as activity in which it was started.
I tried to pass the Me or Activity parameter in the initialize as well.
but i got crash on
it only work with a context.
what would be the correct way to use the activity in which it was started, how to pass the context of the current activity to the SDK?
THXX
i m working to make a startapp lib on B4A and now i have a problem..
the code below is working perfectly in an activity, however when I try to use it in a class it does not start correctly.
I intend to compile it as a library, to use in other projects.
B4X:
Sub Class_Globals
Private StartAppSDK As JavaObject
Private StartAppAd As JavaObject
Private ctxt As JavaObject
Public isReady As Boolean = False
Private AdListenerInterstitial As Object
Private AdDisplayListener As Object
Private EventGeneral As String
End Sub
Public Sub Initialize(EventName As String, AppKey As String, testMode As Boolean)
EventGeneral = EventName
If Not(ctxt.IsInitialized) Then ctxt.InitializeContext
If StartAppSDK.IsInitialized Then Return
'INITIALIZE SDK
StartAppSDK.InitializeStatic("com.startapp.sdk.adsbase.StartAppSDK")
StartAppSDK.RunMethod("init", Array(ctxt,AppKey,True))
StartAppSDK.RunMethod("setTestAdsEnabled", Array(testMode))
'AD LISTENER
StartAppAd.InitializeNewInstance("com.startapp.sdk.adsbase.StartAppAd", Array(ctxt))
AdListenerInterstitial = StartAppAd.CreateEventFromUI("com.startapp.sdk.adsbase.adlisteners.AdEventListener", "AdListenerInterstitial", Null)
AdDisplayListener = StartAppAd.CreateEventFromUI("com.startapp.sdk.adsbase.adlisteners.AdDisplayListener", "AdDisplayListener", Null)
End Sub
Private Sub AdListenerIntersticial_Event (MethodName As String, Args() As Object) As Object 'EVENTOS DO BANNER
Select MethodName
Case "onReceiveAd"
If SubExists(ctxt, EventGeneral) Then CallSub2(ctxt,EventGeneral,"onReceiveAd")
isReady = True
Case "onFailedToReceiveAd"
If SubExists(ctxt, EventGeneral) Then CallSub2(ctxt,EventGeneral,"FailedToReceiveAd")
isReady = False
End Select
Return Null
End Sub
Private Sub AdDisplayListener_Event (MethodName As String, Args() As Object) As Object
Select MethodName
Case "adHidden"
If SubExists(ctxt, EventGeneral) Then CallSub2(ctxt,EventGeneral,"adHidden")
Case "adDisplayed"
If SubExists(ctxt, EventGeneral) Then CallSub2(ctxt,EventGeneral,"adDisplayed")
Case "adClicked"
If SubExists(ctxt, EventGeneral) Then CallSub2(ctxt,EventGeneral,"adClicked")
Case "adNotDisplayed"
If SubExists(ctxt, EventGeneral) Then CallSub2(ctxt,EventGeneral,"adNotDisplayed")
End Select
Return Null
End Sub
Public Sub LoadAd
If StartAppAd.IsInitialized Then StartAppAd.RunMethod("loadAd", Array(AdListenerInterstitial))
End Sub
Public Sub showAd
If StartAppAd.IsInitialized And isReady Then StartAppAd.RunMethod("showAd", Array(AdDisplayListener))
End Sub
Instead of using
B4X:
ctxt.InitializeContext
How can I get the activity in which the class was started?
For example in main I started with the following command.
B4X:
interstitial.Initialize ("test", "999999", True)
interstitial.LoadAd
However, ctxt.InitializeContext is initialized with class and not as activity in which it was started.
I tried to pass the Me or Activity parameter in the initialize as well.
B4X:
Public Sub Initialize(Ac as object, EventName As String, AppKey As String, testMode As Boolean)
B4X:
StartAppSDK.RunMethod("init", Array(Ac,AppKey,True))
it only work with a context.
what would be the correct way to use the activity in which it was started, how to pass the context of the current activity to the SDK?
THXX