Java Question Initializing Object

walterf25

Expert
Licensed User
Longtime User
Hello everyone, i'm in need of some of the experts help, i'm currently wrapping a library for the TapJoy ads.
however i'm not an expert in Java and i need some help.
this is the code in their document to initialize a connection
B4X:
TapjoyConnect.requestTapjoyConnect(Context context, String appID, String secretKey);

this is my code in Java, but i need help initializing the object

B4X:
public class TapJoyAds extends Activity{
  
    public String eventname;
    public TapjoyConnect banner;
  
    public void Initialize(final BA ba, String EventName, String tapjoyAppID, String tapjoySecretKey){
        Hashtable<String, String> flags = new Hashtable<String, String>();
        flags.put(TapjoyConnectFlag.ENABLE_LOGGING, "true");
        eventname = EventName.toLowerCase(BA.cul);
        TapjoyConnect.requestTapjoyConnect(ba.context.getApplicationContext(), tapjoyAppID, tapjoySecretKey, flags, new TapjoyConnectNotifier(){
      
            @Override
            public void connectFail() {
                // TODO Auto-generated method stub
                //ba.raiseEvent(getObject(), eventname + "_connectFailed");  'This won't work unless I Initialize the object
            }

            @Override
            public void connectSuccess() {
                // TODO Auto-generated method stub
            }
      
    });

}}

Any help will be appreciated guys.

thanks,
Walter
 

walterf25

Expert
Licensed User
Longtime User
Remove getObject() and pass null instead.

Are you sure that you need to extend Activity?

Hi Erel thanks for your reply, I actually removed the extend Activity and used
B4X:
ba.raiseEventFromDifferentThread(sender, container, TaskId, event, throwErrorIfMissingSub, params)
method

this works great, now i have another question, i need to get the banner ads to display but i have no idea how to do this, here's the code from their integration instructions.

To integrate Display Ads, you start by calling the following method:
B4X:
TapjoyConnect.getTapjoyConnectInstance().getDisplayAd(Activity activity,TapjoyDisplayAdNotifier notifier);
The getDisplayAd() method requires an Activity context. It should be the activity where the banner is getting displayed. After the ad data has been successfully received, the class implementing the TapjoyDisplayAdNotifier will get a callback in the getDisplayAdResponse(View view) method. You can handle how to display the ad in that method. In most cases, you will want to add the received Display Ad View to your current visible view in order to show the ad to the user.

The following callback method must be implemented in the class implementing the TapjoyDisplayAdNotifier for Ads to work properly:
B4X:
getDisplayAdResponse(View view);

I have this code in Eclipse so far, and i can see in B4A that the ad is received, but i don't know how to display it, can you help me with this please
B4X:
public void BannerAd(final BA ba, String eventName){
    TapjoyConnect.getTapjoyConnectInstance().enableDisplayAdAutoRefresh(true);
    eventname1 = eventName.toLowerCase(BA.cul);
    TapjoyConnect.getTapjoyConnectInstance().getDisplayAd(ba.activity, new TapjoyDisplayAdNotifier(){

        @Override
        public void getDisplayAdResponse(View arg0) {
            // TODO Auto-generated method stub
            ba.raiseEventFromDifferentThread(ba.context, arg0, 0, eventname1 + "_adresponse", false, null);
        }

        @Override
        public void getDisplayAdResponseFailed(String arg0) {
            // TODO Auto-generated method stub
        //ba.raiseEventFromDifferentThread(sender, container, TaskId, event, throwErrorIfMissingSub, params);
        }
       
    });
}

Any tips on how to do this Erel?

Thanks,
Walter
 
Last edited:

walterf25

Expert
Licensed User
Longtime User
Make sure that your class is annotated with @ActivityObject.

Pass the view as one of the events parameters:
B4X:
ba.raiseEventFromDifferentThread(null, null, 0, eventName + "_..", false, new Object[] {arg0});
B4A:
Sub yyy_AdResponse (Ad As View)
Thanks Erel that worked like a charm.
 
Top