I have a java library with the following code:
And in my B4A service:
but when i start the service i get:
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
*** Service (audioservice) Create ***
Error occurred on line: 31 (AudioService)
java.lang.ClassCastException: anywheresoftware.b4a.objects.NotificationWrapper$NotificationData cannot be cast to android.app.Notification
at bass.example.audioservice._service_create(audioservice.java:411)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:738)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:357)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:260)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:171)
at bass.example.audioservice.onCreate(audioservice.java:56)
at android.app.ActivityThread.handleCreateService(ActivityThread.java:3874)
at android.app.ActivityThread.access$2100(ActivityThread.java:229)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1909)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:7410)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
** Service (audioservice) Start **
If i put the same code in activity it works without problems. Is BA object incompatible with service?
B4X:
// Encoder callback
@Events(values={"EncodeProc(int handle, int channel, ByteBuffer buffer, int length, Object user)"})
@ShortName("BASSEnc_EncodeProc")
public static class EncodeProcedure {
private BA ba;
private String eventName;
public void Initialize(BA ba, String EventName) {
this.ba = ba;
this.eventName = EventName.toLowerCase(BA.cul);
}
public BASSenc.ENCODEPROC encodeproc = new BASSenc.ENCODEPROC() {
public void ENCODEPROC(int handle, int channel, ByteBuffer buffer, int length, Object user) {
byte[] b = new byte[length];
buffer.get(b);
ba.raiseEvent(null, eventName + "_encproc", handle, channel, b, length, user);
}
};
}
static {
System.loadLibrary("bassenc");
}
And in my B4A service:
B4X:
Sub Process_Globals
....
Dim Pencopus As BASSEnc_EncodeProc
.....
End Sub
Sub Service_Create
.....
Pencopus.Initialize("myenc")
.....
Notification1.Initialize
Notification1.Icon = "icon" 'use the application icon file for the notification
Notification1.Vibrate = False
Service.StartForeground(1, Notification1)
End Sub
but when i start the service i get:
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
*** Service (audioservice) Create ***
Error occurred on line: 31 (AudioService)
java.lang.ClassCastException: anywheresoftware.b4a.objects.NotificationWrapper$NotificationData cannot be cast to android.app.Notification
at bass.example.audioservice._service_create(audioservice.java:411)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:738)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:357)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:260)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:171)
at bass.example.audioservice.onCreate(audioservice.java:56)
at android.app.ActivityThread.handleCreateService(ActivityThread.java:3874)
at android.app.ActivityThread.access$2100(ActivityThread.java:229)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1909)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:7410)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
** Service (audioservice) Start **
If i put the same code in activity it works without problems. Is BA object incompatible with service?