Java Question How to pass BA Activity to Java Class?

Richard Goh

Active Member
Licensed User
Longtime User
I am trying to wrap a usb printer library. It's have a USBController class (as attached img) to control the usb device and the class is initialize with a Java Activity and handler [ UsbController(Activity, Handler) ]. What shall I use to pass into the class to initialize it?

B4X:
import com.zj.usbsdk.PrintPic;
import com.zj.usbsdk.UsbController;

import android.app.Activity;
import android.hardware.usb.UsbDevice;
import android.os.Handler;
import anywheresoftware.b4a.BA;
import anywheresoftware.b4a.BA.ActivityObject;
import anywheresoftware.b4a.BA.DependsOn;
import anywheresoftware.b4a.BA.ShortName;
import anywheresoftware.b4a.BA.Version;

@DependsOn(values={"usbsdk", "android-support-v4"})
@ShortName("USBPrinter")
@Version(1.0f)
@ActivityObject

public class USBPrinterWrapper {
    UsbController  usbCtrl = null;
    UsbDevice dev = null;
    private int[][] u_infor;
    private byte isHasPaper;
    private Handler mHandler;
   
    public void Initialize(BA ba, String EventName) {
        usbCtrl = new UsbController(ba, mHandler);
    }
 

Attachments

  • usbprint.JPG
    usbprint.JPG
    44.9 KB · Views: 301

Douglas Farias

Expert
Licensed User
Longtime User
Thanks, that seemed to work. Then I have a simiar issue with extending my abstract class from Activity. What should i include in this case? And a similar one is with AsyncTask.
Thanks for assistance.
 

hears

Active Member
Licensed User
Longtime User
I am trying to wrap a usb printer library. It's have a USBController class (as attached img) to control the usb device and the class is initialize with a Java Activity and handler [ UsbController(Activity, Handler) ]. What shall I use to pass into the class to initialize it?

B4X:
import com.zj.usbsdk.PrintPic;
import com.zj.usbsdk.UsbController;

import android.app.Activity;
import android.hardware.usb.UsbDevice;
import android.os.Handler;
import anywheresoftware.b4a.BA;
import anywheresoftware.b4a.BA.ActivityObject;
import anywheresoftware.b4a.BA.DependsOn;
import anywheresoftware.b4a.BA.ShortName;
import anywheresoftware.b4a.BA.Version;

@DependsOn(values={"usbsdk", "android-support-v4"})
@ShortName("USBPrinter")
@Version(1.0f)
@ActivityObject

public class USBPrinterWrapper {
    UsbController  usbCtrl = null;
    UsbDevice dev = null;
    private int[][] u_infor;
    private byte isHasPaper;
    private Handler mHandler;
  
    public void Initialize(BA ba, String EventName) {
        usbCtrl = new UsbController(ba, mHandler);
    }
have you finish your libary ?i have same problem now.
 
Top