I'm becoming crazy ..
As I start the program, I have to check if a file exists. If not I want to end the activity and start another one.
Below the code. The file does not exist, I see "Nomaps" in the log, but also "why am I here ?"
It seems that after the Activity.finish some lines of code are executed, before the activity is really finished and started the other one.
Any help ?
Marco
Sub Activity_Create(FirstTime As Boolean)
If File.Exists(File.DirRootExternal & "/test.map") =False Then
Log("Nomaps")
Activity.Finish
StartActivity(NoMaps)
End If
Why are you trying to finish the current activity before you call the new one?
You should move this code to Activity_Resume and just call the next activity. When that second activity is finished, it will return to the calling activity. Then set a test to determine if you wish to close the current activity or not.
Hi Margret,
if that file does not exists, i definitely need to close the main activity and start a new one that do other things.
But the activity does not stop at line activity.finish and continue some lines and generate some errors (because that file does not exists).
Also if I do not use activity.finish and simply start a new activity, I see in the log some errors, generated from the code after the line
Log("why am I here ?").
This code (and the following) should not be executed because I have switched to another activity (NoMaps).
I understand, but that kind of code should be outside of Activity_Create. Activity_Create should be used for setting the layout, views, location, etc. Once the Activity_Create is finished, then do the code to test for this file and call another activity. Move that code out of Activity_Create. This is most likely why you are having the issues.
mmmhhh ... sure I'm missing some fundaments of b4a programming, but I have difficulties to understand.
Suppose I have a piece of code that open that file and show its contents in a label.
Before opening the file, I check if exists or not.
But after I see the file does not exists and switch to another activity, the code in the main continue and open the file, generating the error.
I don't understand: where should I have to put that code that check for the file if not in the activity create ?