Activity.Finish

rfresh

Well-Known Member
Licensed User
Longtime User
I have two activities, Main and Setup. When I click on a button on my Main screen, I'm calling it's Activity.Finish method and while it goes away, the Setup screen displays! I wasn't expecting this behavior. I was expecting the app to pause and the home screen to display again on the phone. What might be causing the Setup screen to display?

Thanks...
 

JonPM

Well-Known Member
Licensed User
Longtime User
Please post code. you shouldn't call Activity.Finish when clicking out of main

Sent from my DROIDX
 
Upvote 0

rfresh

Well-Known Member
Licensed User
Longtime User
Here is my button click event that I want to do some stuff then close (Pause?) the app:


B4X:
Sub btn_Indoor_Click
Update_Button_Faces
Write_To_Dat_File
Activity.Finish
End Sub
 
Upvote 0

JonPM

Well-Known Member
Licensed User
Longtime User
Here is my button click event that I want to do some stuff then close (Pause?) the app:


B4X:
Sub btn_Indoor_Click
Update_Button_Faces
Write_To_Dat_File
Activity.Finish
End Sub

what is write to dat file, is that another activity?

Sent from my DROIDX
 
Upvote 0

rfresh

Well-Known Member
Licensed User
Longtime User
write_to_dat_file is a sub that writes some app data (4 Int items) to a file in case the app, while not active, is killed by the OS.

Update_button_faces is also a sub.
 
Upvote 0

warwound

Expert
Licensed User
Longtime User
Presumably at some point before calling Activity.Finish in your Main activity your Setup activity has been run?

If so then what you're seeing is the default Android behaviour.

When you go from activity to activity the previous activity is added to the activity stack.
When the current activity stops, the last activity to be added to the activity stack is started.

See this link for some useful info: Tasks and Back Stack | Android Developers.

The solution (i think) is to call Activity.Finish in your Setup activity when it is stopped.
That should prevent it from being added to the activity stack - so when your Main activity stops the Setup activity will not be on the stack so will not be started.

Martin.
 
Upvote 0
Top