Hey JordiCp, thanks for this code it works perfectly in the demo. When I drop the oservice into a project and just call it with the lines
Code:
Starter.MYSERVICE=True
StartService(oService)
'
the service is called but then hits an error at this line
Code:
myChatHead.instance=J.RunMethod("newInstance2",Array(J,id))
The error message I get is
*** Service (oservice) Create ***
** Service (oservice) Start **
Error occurred on line: 129 (oService)
java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:131)
at aus.anyfcsapp.joe.oservice._init_elements(oservice.java:357)
at aus.anyfcsapp.joe.oservice._service_start(oservice.java:641)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:710)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:339)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:249)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:139)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:166)
at aus.anyfcsapp.joe.oservice.handleStart(oservice.java:116)
at aus.anyfcsapp.joe.oservice.access$000(oservice.java:19)
at aus.anyfcsapp.joe.oservice$1.run(oservice.java:81)
at anywheresoftware.b4a.objects.ServiceHelper$StarterHelper.onStartCommand(ServiceHelper.java:105)
at aus.anyfcsapp.joe.oservice.onStartCommand(oservice.java:79)
at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2990)
at android.app.ActivityThread.access$2200(ActivityThread.java:175)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1405)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:146)
at android.app.ActivityThread.main(ActivityThread.java:5602)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.WindowManager$BadTokenException: Unable to add window android.view.ViewRootImpl$W@42a86718 -- permission denied for this window type
at android.view.ViewRootImpl.setView(ViewRootImpl.java:793)
at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:278)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69)
at aus.anyfcsapp.joe.oservice$CustomImageView.sharedConstructing(oservice.java:721)
at aus.anyfcsapp.joe.oservice$CustomImageView.<init>(oservice.java:689)
at aus.anyfcsapp.joe.oservice.newInstance2(oservice.java:855)
... 30 more
I get the error no mater if i add the line activity.finish or not in the calling of the service
Can you advise of a possible solution?
Thanks again