Android Question StartActivit don't work under Service

gameone

Member
Licensed User
Hi i am using
StartActivity(Phone3.Call("123"))
To call directly someone.

This work fine under Main or Even Service.
The only problem is when i do it under Service, this is causing service stopped!

There is a way to prevent this? I want service resume and do his job and don't be stopped when StartActivity is called.

This is done under:
Sub JobDone (Job As HttpJob)

End Sub.


Thanks u.
 

DonManfred

Expert
Licensed User
Longtime User
I guess you should use CallSubDelayed and call a sub in your activity which then do the start activity (to call).
 
Upvote 0

MFfromGermany

Member
Licensed User
I'm still kind of a rookie, too. But as far as I know your problem could be like this:

You start your service, the service handles "Service_Start" and then "Service_Resume". Somewhere in between these two subs there's your code. And as soon as your code is done the service is done doing its job. I think (and I may be wrong, if so then I apologize) this job won't be done again unless you call "StartService" again.

But if it works the way you did it, then maybe this could be your solution:

Calling "Sub startActivityFromService" which is in your main activity:
B4X:
CallSub(Main, "startActivityFromService")

Or if you got a sub in your service which should start the activity you can use:

B4X:
CallSub(Me, "startActivityFromService")

I hope that helps.
 
Last edited:
Upvote 0

gameone

Member
Licensed User
Yeah MFFromGermany.
Thats why i already put StartService(me) in Service_start at the end.

At begin of my program i add too
Log("service ok")

@Erel
Infact when instead of doing a call i open a website that work fine job is done and service is restarted when job is finished.
I can see though debug

But with startactivity when call is make, debugger is stopping, and service sont restart.


@DonManfred
Look a good idea i will try when back to work on.
 
Upvote 0

gameone

Member
Licensed User
@Erel Okay will try on smartphone on APK and not inside emulator.

@Other
About CallSubDelayed that work fine, service is restart in emulator too.
But that's causing a crash into service i wrote this:

Sub JobDone (Job As HttpJob)

CallSubDelayed(call_phone,Me)
Log("test")


End Sub

Sub call_phone

'CALL NUMBER
StartActivity(Phone3.Call("123"))
End Sub




All got working, call is showed and too i can see message "example" working fine, but that causing too a crash:

** Activity (main) Pause, UserClosed = false **
java.lang.RuntimeException: java.lang.Exception: Sub class b4a.example.tt was not found.
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:165)
at anywheresoftware.b4a.BA$2.run(BA.java:328)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5001)
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:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.Exception: Sub class b4a.example.tt was not found.
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:140)
... 10 more
 
Upvote 0

gameone

Member
Licensed User
@Erel
Android program is crashing too with java exception.
See the problem is fixed when you switch from "Debug" to "Release".

Thanks u for your support.
 
Upvote 0
Top