Android Question Navigating back to a prior-to-last Activity

swabygw

Active Member
Licensed User
Longtime User
Sorry if this is a simplistic navigation question, but here goes: I have an application with, say, four or five Activity's, with Activity 1 being the Main Activity (Act), and the application has a navigation menu, too. The Activity_Create looks is basic like this:

B4X:
Sub Activity_Create(FirstTime As Boolean)
  If FirstTime Then
    PopulateLayout 'populates the child views onto the layout
  End If
End Sub

Here are the navigation steps:
1) From Main (Act 1), click on something (not the menu) which takes me to Act 2, via the "StartActivity" command. Act 1 does not receive the "Activity.Finish" command because it should still be running and available to come back to.
2) Then, from Act 2, I click on something that takes me to Act 3. Act 2 gets the "Activity.Finish" command and is killed, and then Act 3 is started using the "StartActivity" command.
3) Lastly, in Act 3, to go back to Act 1 (Main), I have two choices available: a) the Back button, or b) the menu. Which brings me to the following questions.

Question 1) If I click the Back button from Act 3, which Act do I go back to? I'm guessing the answer is Act 1 because Act 2 was killed. But, this scenario isn't my real issue - the next question is my real issue.

Question 2) Here's where I'm stumped - if I use the menu and click an item to go back to Act 1 directly, which executes "Activity.Finish" and "StartActivity(Main)", the layout is gone and the screen is empty because I used the "If FirstTime Then PopulateLayout" as described above. If I comment out the FirstTime condition and say just "PopulateLayout", then it works correctly. But, I'm thinking that this creates duplicate child views (granted, I could use the RemoveAllViews command).

I'm thinking that there must be a better way to navigate back to Act 1 (Main) than the way that I'm doing it. For example, should I really be using StartActivity(Main) when Main is/was already started and I just want to return to it, or is there another way to command to go to Main other than StartActivity?

Apologies for the length, but any recommendations are appreciated!
 
Last edited:

swabygw

Active Member
Licensed User
Longtime User
Thanks for the replies. It sounds like re-executing PopulateLayout, when going back to the Main activity, is the correct way. Would you agree that StartActivity(Main) is the correct way to navigate back to, and resume, Main?
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…