How to exit application?

prokli

Active Member
Licensed User
Longtime User
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
 

prokli

Active Member
Licensed User
Longtime User
Thanks, Erel!

I already build a project version, which starts the servive in "Activity_Create" independently of "FirstTime" flag.
BUT: what happens if I rotate may tab?
Service will be re-created while it is still running. This didn't work!
 
Upvote 0

wes58

Active Member
Licensed User
Longtime User
Since the topic is "How to exit application?", I thought I will ask a question.
I have two Activities. I call second Activity from the first one using StartActivity(gpslocation).
In the Second Activity I have a Button Quit. If I press this button I want to exit application not to go to the first Activity.
I put in button Quit_Click subroutine, Exit Application, but it doesn't close application, it goes to the first Activity. I tried putting Activity.Finish and ExitApplication, but it does the same thing.

Is there a way to close (completely) application from from the second activity?
 
Upvote 0
Top