Var Activity assigning

marcel

Active Member
Licensed User
Longtime User
Hi,

I have a Class Module that makes as buttonBar. In the class module I start the activities depending on the btn clicks.

In all those clicks I have something like:

If LastActivity<>ListActivity Then
LastActivity.Finish
End If
LastActivity=ListActivity
StartActivity(ListActivity )

The LastActivity variable is a global process variable (Dim LastActivity as Activity).

I am doing this to clean all the unneeded activities.

Unfortunatly this won't compile because I cannot compare LastActivity<>ListActivity?

How can I solve this?
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
You cannot access other activities from the class.

The bar is always a child of a specific activity. You can store a reference to this activity in the Initialize method and then call Finish to close the current activity.

You can also store the activity name and then compare it to the target activity (to test whether the user has pressed on the current activity button).
 
Upvote 0

marcel

Active Member
Licensed User
Longtime User
You cannot access other activities from the class.
You can also store the activity name and then compare it to the target activity (to test whether the user has pressed on the current activity button).

That's what I did? didn't I? But the compiler does not allow me to compare?

Is there a way to close all open activities? Some kind of process list where I can loop trough?
 
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
That's what I did? didn't I? But the compiler does not allow me to compare?

Is there a way to close all open activities? Some kind of process list where I can loop trough?

No, you didn't. You declared activity objects :)

What I do to close all open activities, which I am not sure if it's a correct one, is this:

I set a flag, name it closeAllOpenActivities, to true. Then, inside the activity_resume sub of each activity, I check for this flag, and if true, I close the activity. I then, have a timer triggered in the main activity when flag is true. It waits until another variable contains the number of the other open activities. It increases at activity_pause of them when flag is true. Then I close the main activity. All these are happening because I need speed in opening some core activities, otherwise I don't see a reason for such process.
 
Upvote 0

marcel

Active Member
Licensed User
Longtime User
I set a flag, name it closeAllOpenActivities, to true. Then, inside the activity_resume sub of each activity, I check for this flag, and if true, I close the activity. I then, have a timer triggered in the main activity when flag is true. It waits until another variable contains the number of the other open activities. It increases at activity_pause of them when flag is true. Then I close the main activity. All these are happening because I need speed in opening some core activities, otherwise I don't see a reason for such process.

What do you think about this. I have a list with a type (name and activity) and I add all new created activities to this list. When I need to close I call a helper which walks trough this list and close the activities in this list?

Make this sense?
 
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
sure but i have a question: why not closing the activities upon back-key press?
 
Upvote 0

marcel

Active Member
Licensed User
Longtime User
sure but i have a question: why not closing the activities upon back-key press?

Ok. I need to explain my design.

I have a class module which creates a button bar in the bottom. (5 pieces). The first activity will start and the first btn will be active. When a user click another button the class module starts the activity that belongs with the btn bar. So I am not allowing the user to use the back key and close that activity. Every activity has a var to the bar type and creates the btn bar with the current one highlighted. So when the user choose the menu close app then I would like to close all open activities.

I did use this design because I didn't want to create the btn bar in all the activities.

Maybe my design is wrong but this is my first app using B4A (I have expierence in VB.NET and Objective C).
 
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
I understand now.

When you click a button, set a boolean flag, name it closePrevActivity to true. If you think about it, when you startActivity the new activity, the activity_pause of the previous activity will fire. Inside this sub, check for closePrevActivity and thus use activity.finish (this is in order to differentiate between a startActivity and a normal activity_pause event). Also, don't forget to set closePrevActivity to false. Something like this:
B4X:
sub btn_click
dim a as string
a=btn.tag
startactivity(a):' now I know it should be an object, but I think a string will work as well
closePrevActivity=true
end sub

sub activity_pause(blah blah)
if closePrevActivity=true then
closePrevActivity=false
activity.finish
end sub
 
Upvote 0

marcel

Active Member
Licensed User
Longtime User
B4X:
sub btn_click
dim a as string
a=btn.tag
startactivity(a):' now I know it should be an object, but I think a string will work as well
closePrevActivity=true
end sub

sub activity_pause(blah blah)
if closePrevActivity=true then
closePrevActivity=false
activity.finish
end sub
Ok, thanks. Imwill work out something based on this thougth.
 
Upvote 0
Top