Hello everybody!
Could you give me some ideas, how to deal with the "Android Process and activities life cycle". Believe me, I have read this chapter several times and I fear, that I still don't understand it.
Following scenario:
My project keeps one activity including a so called "Exit" button and a service (ComServ) running in background. Typing the exit button, I would like to finish my application!
That's the simplified code of my activity
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("StartScreen")
If FirstTime Then
' right here I start the service
StartService(ComServ)
End If
End Sub
Code of Exit button:
Sub ExitButton_Click
StopService(ComServ)
Activity.Finish
End Sub
Now, what happens?
If I type the exit button, the service is destroyed and the activity goes into "Pause" mode ( I can see both events on the Log window of the IDE). If I restart the application, the activity moves from "Pause" to "Create" to "Resume". But - and this is the thing what makes me foolish - the "FirstTime" variable is set "False" and therefore the service won't be started again. Bad thing!
If I modify the code of exit button, it works!
Sub ExitButton_Click
StopService(ComServ)
ExitApplication
End Sub
As I have read several times in this forum, using "ExitApplication" is not the appropriate way to exit applications. So what is the best way???
Regards,
Harald
Could you give me some ideas, how to deal with the "Android Process and activities life cycle". Believe me, I have read this chapter several times and I fear, that I still don't understand it.
Following scenario:
My project keeps one activity including a so called "Exit" button and a service (ComServ) running in background. Typing the exit button, I would like to finish my application!
That's the simplified code of my activity
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("StartScreen")
If FirstTime Then
' right here I start the service
StartService(ComServ)
End If
End Sub
Code of Exit button:
Sub ExitButton_Click
StopService(ComServ)
Activity.Finish
End Sub
Now, what happens?
If I type the exit button, the service is destroyed and the activity goes into "Pause" mode ( I can see both events on the Log window of the IDE). If I restart the application, the activity moves from "Pause" to "Create" to "Resume". But - and this is the thing what makes me foolish - the "FirstTime" variable is set "False" and therefore the service won't be started again. Bad thing!
If I modify the code of exit button, it works!
Sub ExitButton_Click
StopService(ComServ)
ExitApplication
End Sub
As I have read several times in this forum, using "ExitApplication" is not the appropriate way to exit applications. So what is the best way???
Regards,
Harald