Newbie here, b4a behavior question

jflaplante

Member
Licensed User
Longtime User
Hi,

I'm relatively new to b4a and I began working on my first application last monday.

My question is with the behavior of b4a while switching between activities.


Activity 'main' load a layout and has a Listview that is filled up with invoice summaries by an sql request. The click event stores the selected item in a global variable and starts activity 'display_header'.

Activity 'display_header' loads a layout, makes an sql request and display an invoice header.

This works very well on the first try. Now here's the problem I have:

The 'display_header' activity also has a 'summary' button which does a 'StartActivity(Main)'.

Behavior A:
When I click the 'summary' button, the screen goes back to the 'main' activity and the listview as it should but then when I click on a different item on the listview other than the first time, the 'display_header' activity still display the first invoice header. As if the 'value' of the listview and the variable aren't changed.

Behavior B:
When I use the tablet 'back' button instead, the screen also goes back to the listview but this time, when I select a different item; the right invoice header is displayed in the 'display_header' activity.


Why is b4a behaving in two different ways for the 'apparent' same operation?

I'm sure this is somehow normal and I'm missing a small thing but I thank you in advance for any help you can give me. I have a few other questions that I will ask later in another post after searching the forum first.

JF.
 

jflaplante

Member
Licensed User
Longtime User
Don't use StartActivity(Main), use Activity.Finish. This is the same as the Back Key.

Thanks, I tried it and it works but I still have situations where it is not working properly.

- When I'm 3-4 activity 'deep' and I want to return to the first one, a simple 'back' will no work, I need to be able to jump to the desired activity.

- In one case, I have an activity where I edit an invoice line. The 'save' button click event issue an sql command to save the changes and does an 'activity.finish' as you suggested. The changes are saved but I don't see them on the previous screen where a listview of all the invoice lines are shown. I see the previous values. When I go back to the previous activity where the invoice header is displayed and then go back to the invoice detail listing I can see the changes.

I guess what would best describe my need is to 'restart' the activity_create sub and repopulate the layout. Is such a thing possible. I will try to play with the activity_resume sub to see what hapens. I hesitate to do so because I feel like I would be duplicating code.

Thanks.

JF.
 
Upvote 0

margret

Well-Known Member
Licensed User
Longtime User
You should move the code that populates the data to a new sub you create. The activity_create is really just for the layout of the objects needed in the activity. That way you can have a process global variable that you can check in Activity_Resume to determine what subs to call when you return to the main activity. The process global can be set to any value you need and can be set from any activity. In other activities use the main activity name to access the variable like: main.myvar = ""
 
Upvote 0
Top