Android Tutorial Service Modules

LucaMs

Expert
Licensed User
Longtime User
I tested this code.

After closing the app (close button, ExitApplication) I can't see any process nor service in the "task manager".

I have not stopped the service, it should then restart the process, according to what was said in that post.
 

Attachments

  • lm ServiceTest.zip
    12.7 KB · Views: 665
Last edited:

Straker

Active Member
Licensed User
Longtime User
I tested this code.

After closing the app (close button, ExitApplication) I can't see any process nor service in the "task manager".

I have not stopped the service, it should then restart the process, according to what was said in that post.

You don't see services in taskmanager.
I cannot see your zip now. But probably your service has just ended and you don't have rescheduled it.

Therefore I think we're saying the same thing.
You say the closing the activity also the service dies, I'm saying that that the service is still running...
We have to test with a service that write the ticks in a file and see if the tick count increases also when the app is killed, or only when the service restart because scheduled.

Summary: does a service, with a long running task, continue to run after an activity.finish? And after an ExitApplication?
I say yes. The only way to programmatically stop a service is, I think, with ServiceStop.
HELP - Can someone answer the question?
 

LucaMs

Expert
Licensed User
Longtime User
Summary: does a service, with a long running task, continue to run after an activity.finish? And after an ExitApplication?
I say yes. The only way to programmatically stop a service is, I think, with ServiceStop.

Summary: does a service, with a long running task, continue to run after an activity.finish?

Activity.Finish closes the Activity, not the app (the process)!
You could start a service from within 3 of the 10 activities that compose your app or from a code module!

After ExitApplication: that post says that ExitApplication works only if you close any activity and stop any service and, if a service is not stopped, the process restarts. In that my test, I do not see the restart of the process.
 

Straker

Active Member
Licensed User
Longtime User
Ok, we have to check what happens to a service after ExitApplication. It's a good task for tomorrow...
 

Straker

Active Member
Licensed User
Longtime User
Summary:
A process is made by activities and services.
If the current activity is terminated with Activity?Finish, the service(s) is still alive.
If the app is terminated with ExitApplication also the services are terminated.
BUT if there is a scheduled service, this services will be created at the scheduled time.
...the 3rd proposition is to be checked...
 

Straker

Active Member
Licensed User
Longtime User
I tested this code.

After closing the app (close button, ExitApplication) I can't see any process nor service in the "task manager".

I have not stopped the service, it should then restart the process, according to what was said in that post.

You don't see the services. When 'task manager' is empty I have a couple of my services running (I know they are running because they beep every minute) and I think a lot of other services.

Probably you are perfectly right. ExitApplication kills also the service and if there is no scheduling, everything is dead.

Tomorrow I'll try to ExitApplication and see what happens to the service. Will it still beep or not? Who wants to bet?
 

DarkAngel

Member
Licensed User
Longtime User
Hi Erel,


I'm having an issue,


Suddenly my app stop calling a service, and when I use Callsub3(..) it returns:

“…

java.lang.NumberFormatException: Invalid double: "null"

…”

But it works with a backup that I have.

Could the project be corrupted or something is missing so the service it’s not starting.

I’m starting the service on activity create but it’s not starting the service… StartService(SEGUNDO_PLANO)
 

DarkAngel

Member
Licensed User
Longtime User
Here's the full error:
Copying updated assets files (3)


** Activity (main) Create, isFirst = true **


** Activity (main) Resume **


Error occurred on line: 586 (main)
java.lang.NumberFormatException: Invalid double: "null"


at java.lang.StringToReal.invalidReal(StringToReal.java:63)
at java.lang.StringToReal.parseDouble(StringToReal.java:269)
at java.lang.Double.parseDouble(Double.java:295)
at anywheresoftware.b4a.BA.ObjectToNumber(BA.java:622)
at com.roundsquarebox.radar.main._preenche_lista_alertas(main.java:2283)
at com.roundsquarebox.radar.main._update_screen(main.java:795)
at com.roundsquarebox.radar.main._activity_resume(main.java:1019)
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:636)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:305)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:238)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:121)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:171)
at com.roundsquarebox.radar.main.afterFirstLayout(main.java:106)
at com.roundsquarebox.radar.main.access$100(main.java:17)
at com.roundsquarebox.radar.main$WaitForLayout.run(main.java:78)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5356)
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:1265)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
at dalvik.system.NativeStart.main(Native Method)

and the line 586 is: "If ((CallSub3(SEGUNDO_PLANO,"DEVOLVE_TEMPO",pnl_ALERTAS.Tag,"s")<=SEGUNDO_PLANO.int_REFRESH_RATE) AND (pnl_ALERTAS.Tag <>"")) OR Not(SEGUNDO_PLANO.bln_COMPRADO) Then Return"

Can't find a reason for this...that null makes no sense to me...
 

DarkAngel

Member
Licensed User
Longtime User
Hello Erel,

I just found what was causing the error...

I was calling the SERVICE before it was created, now it’s working fine.

 

DarkAngel

Member
Licensed User
Longtime User
My service module is being stope when I make a memory clean. Since I use notifications, the notification stays alive and wont be removed until I restart the app again.
The Service_Destroy is not being called this way. Any way that I can remove the notification when the service is stop by the system?
 

John Decowski

Member
Licensed User
Longtime User
Will a service module run when the app isnt running?? Like for notifications when app not currently running?
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…