Firsttime in activity_create

bees

Member
Licensed User
Longtime User
Sub Activity_Create(FirstTime AsBoolean)
If FirstTime = TrueThen
Msgbox("Firsttime", "This is the firsttime")
Else
Msgbox("Firsttime", "Should not be here")
EndIf
End Sub

I have a problem with FirstTime.
If I make a test program with only the above code it
works as expected when I compile and start the program

from B4A.
When I than quit the program and start it again by
pressing the icon on the device it seems that firsttime = False.
Could this be related to the device?
Samsung Galaxy Y with Android 2.3.5
 

Merlot2309

Active Member
Licensed User
Longtime User
Hello Bees,

First time works correct.
The same compiled apk was first started from B4A and then from your device.
If you copy the apk file to your device yourself, you will see the message.

Succes en groeten,
Helen.
 
Upvote 0

bees

Member
Licensed User
Longtime User
Hello Bees,

First time works correct.
The same compiled apk was first started from B4A and then from your device.
If you copy the apk file to your device yourself, you will see the message.

Succes en groeten,
Helen.

Hello Helen,

The same problem when I copy the apk to the sdcard and install from there. If I press open after the installation it works as expected. Closing the app and start it again the wrong message is shown

Dank je,

Stephen
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
When you close an application it is not directly closed. The OS closes it at some time depending on the memory lacks and requirements. So when you close an app and you restart it again, FirstTime will mostly not be True because the app was not yet closed, this makes starting app faster.

Best regards.
 
Upvote 0

Merlot2309

Active Member
Licensed User
Longtime User
Hoi Stephen,

Dutch: FirstTime is echt alleen de 1e keer; als je bv een database wilt kopieren van de harde schijf naar device.
Als je iets wilt instellen dat iedere keer als de app wordt gestart wordt uitgevoerd, dan gebruik je Activity_Create.
Ik hoop wel dat ik je goed begrijp.

Helen
 
Upvote 0

bees

Member
Licensed User
Longtime User
When you close an application it is not directly closed. The OS closes it at some time depending on the memory lacks and requirements. So when you close an app and you restart it again, FirstTime will mostly not be True because the app was not yet closed, this makes starting app faster.

Best regards.

Ok I understand, took out the battery and then it works ok.
Is there a way to force the closing of an app.
For now I just use a global variable and reset it when the back key is pressed.

Thanks,

Stephen
 
Upvote 0

bees

Member
Licensed User
Longtime User
Hoi Stephen,

Dutch: FirstTime is echt alleen de 1e keer; als je bv een database wilt kopieren van de harde schijf naar device.
Als je iets wilt instellen dat iedere keer als de app wordt gestart wordt uitgevoerd, dan gebruik je Activity_Create.
Ik hoop wel dat ik je goed begrijp.

Helen

Hoi Helen,
Gebruik het inderdaad om te kontroleren en indien nodig kopieren van
een database, maar ook om wat variabelen te zetten.

Dank je,

Stephen
 
Upvote 0

HarryB

New Member
Licensed User
Longtime User
FirstTime vs Global

In the example of SMTP you put the initialisation in Activity_Create/ Firsttime. I had problems with it as firsttime did not always fire (is logical, but not easy).

I therefore moved the initialisation code to Globals which works fine.

Sub Globals
SMTP.Initialize("smtp.gmail.com", 465, "[email protected]", "xxx", "SMTP")
SMTP.UseSSL = True 'Gmail requires SSL.
End Sub


Now I am wondering if this is officially supported as in all text that I read, Global seems to be for initialisation of variables only.

Can you shed some light about the differences?
 
Upvote 0

BasicBert

Member
Licensed User
Longtime User
I know Erel doesn't like it, but you could use ExitApplication which forces the app to close (FirstTime should be true on subsequent runs)

Well, I do like it, as for now ExitApplication releases me from some unwanted behaviour that i couldn't otherwise correct.

My current project shows data from an CSV-file into a choice of three listviews of which one at a time is shown (using the Visible parameters). From this listview a choice is made for an item that then will be shown for all fields of that item in a new listview. After the user closes this view, it returns to the former.

This all works well, except when the app gets closed by the user with the BACK-key and then restarted from the icon or from the recent apps list.

Then, when an item is selected and the second list pops up, I get an error message which states that an index of an array I keep track off is out of bound, although it should have reinitialized to 0 and I have no idea why the program is getting into the routine that uses the variable.

I see the same behaviour and exact the same error either if I show the second list in a separate activity or if I show the second list in the same activity but in a different panel.

ExitApplication, as for now, solved this problem for me. I just wonder what really is the problem, though.
 
Upvote 0

warwound

Expert
Licensed User
Longtime User
Have a read of the Android Process and activities life cycle, it might help you better understand what Android does with an Activity when you exit it or move on to another Activity.

Are you using Process_Global variables and finding that when you return to your Acitvity that the Process_Global variable is no longer initialized?

Martin.
 
Upvote 0

BasicBert

Member
Licensed User
Longtime User
Have a read of the Android Process and activities life cycle, it might help you better understand what Android does with an Activity when you exit it or move on to another Activity.

Are you using Process_Global variables and finding that when you return to your Acitvity that the Process_Global variable is no longer initialized?

Martin.
Thanks for the link, I have read it a few times before. As far as it is possible, I understand closing and resuming activities. But it doesn't explain why the described out of range message is popping up.
The only place where this variable i is used is in the second activity and it is not shared other then in this sub that populates a list of 46 items. Once closed and restarted the activity reports an out of range error for i, whose value then is 47.

With ExitApplication to close the activities, I know it shuts down the whole activity so it has to be rebuild when restarted. Since this prevents the out of range error, I'm fine with that.

In the meantime I have moved from starting a second activity to showing just a second panel above the first one. This works out very fine and is a bit faster. Only drawback is that I will need an additional 4 panels for showing data later in the app, which could make it difficult to define in the Designer.
 
Upvote 0
Top