Thank you very much Erel
@Erel you are right I'm looking for a better solution to my problem.Why do you need to restart it? Don't stop it and it will always run (while your process is alive).
Starter.so.Close Starter.so.Connect (host, port, 0)
' STARTER SERVICE Sub Process_Globals Dim TestVar As String End Sub
'MAIN ACTIVITY (or anywhere the Starter variables are used) Sub Activity_Create(FirstTime As Boolean) Starter.testvar End Sub
testvar = "x" 'if declared within starter, this code would be (within MAIN and all modules and services) Starter.testvar = "x"
** Activity (main) Pause, UserClosed = false ** ** Activity (main) Create, isFirst = false ** ** Activity (main) Resume **
Read post #1 of this threadNo one has yet said how to make the starter service ?
- The Starter service is identified by its name. You can add a new service named Starter to an existing project and it will be the program entry point.
- This is an optional feature. You can remove the Starter service.
- You can call StopService(Me) in Service_Start if you don't want the service to keep on running. However this means that the service will not be able to handle events (for example you will not be able to use the asynchronous SQL methods).
- The starter service should be excluded from compiled libraries. Its #ExcludeFromLibrary attribute is set to True by default.
- The starter service should never be explicitly started. This means that if you want to start a service at boot then add a different service.
This would really be a huge idiocy of Android (it is how Android "works", right, not a b4A "bug")!If the os kills your app while it is in the background then it can resume from the last activity.
Yes.Are you sure?
This is logical. It is what you do on Windows, using more than one sw at the same time. But if you "kill" (close) one of this sw and open again it, it will not start "randomly", but from the entry point, from the beginning (yes, I know, you created the Starter Service for this reason but I think this is a workaround of a big defect of Android.If the user switches to a different app, maybe to copy some text related to your app, and quickly returns to your app then the user expects to return to the same point.
This solution, used only for rare cases where the app is killed by the operating system, may have contraindications (Activities will start from Activity_Create and not from Resume).You can kill all activities when they are paused and the app will start from the main one.
Me too; I think it is more than hugeI don't think that it is a huge idiocy of Android.
You can kill all activities when they are paused and the app will start from the main one.
Could this last "mehod" create problems (related to queued calls, adding StartActivity(Main) as last statement in Service_Start)?If so, I don't see other way to handle this case that ALLWAYS start Main directly from Service_Start... or not? And if I do so, might Main run twice (will two calls added to a queue?)
The starter service feature is quite complicated. Under the hood the target activity or service start the starter service and make sure that Service_Create of the starter service is called before the target module code starts.If this is Android's behavior, how did you make Starter always run first in any situation, even after the system killed the app when it was in background?
B4A will not change the default Android behavior. If you want to do it in your app then there are all kinds of ways to do it. For further discussion you should start a new thread.The authors of the Android could do the same thing, so that Main is always started first.
Or maybe you can do it.