Problem with Directional Buttons on my application - Left, Right and Main Button Page

Joel Fonseca

Member
Licensed User
Longtime User
Hi,

In my application I have 3 activity's:

Main
SairamdoSite1
SairamdoSite2

Main Activity code

B4X:
'Activity module
Sub Process_Globals
   'These global variables will be declared once when the application starts.
   'These variables can be accessed from all modules.
   Dim MediaPlayer1 As MediaPlayer

End Sub

Sub Globals
   'These global variables will be redeclared each time the activity is created.
   'These variables can only be accessed from this module.
   

End Sub

Sub Activity_Create(FirstTime As Boolean)
   Activity.LoadLayout("menu_principal")


End Sub


Sub SairamdositeButton1_Click
      Mediaplayer1.Initialize
      MediaPlayer1.Load(File.DirAssets, "Click1.wav")
      MediaPlayer1.Play
     
      StartActivity(SairamdoSite1)
      
End Sub





Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

SairamdoSite1 Activity code

B4X:
'Activity module
Sub Process_Globals
   'These global variables will be declared once when the application starts.
   'These variables can be accessed from all modules.
   Dim MediaPlayer1 As MediaPlayer

End Sub

Sub Globals
   'These global variables will be redeclared each time the activity is created.
   'These variables can only be accessed from this module.

End Sub

Sub Activity_Create(FirstTime As Boolean)
   Activity.LoadLayout("sairamdosite1")
   
End Sub



Sub SetaEsquerdaButton1_Click
      Mediaplayer1.Initialize
      MediaPlayer1.Load(File.DirAssets, "Click1.wav")
      MediaPlayer1.Play
        
      Activity.Finish
   
End Sub

Sub SetaDireitaButton1_Click
      Mediaplayer1.Initialize
      MediaPlayer1.Load(File.DirAssets, "Click1.wav")
      MediaPlayer1.Play
        
      StartActivity(SairamdoSite2)
   
End Sub

Sub SetaPrincipalButton1_Click
      Mediaplayer1.Initialize
      MediaPlayer1.Load(File.DirAssets, "Click1.wav")
      MediaPlayer1.Play
        
      Activity.Finish
   
End Sub


Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub


SairamdoSite2 Activity Code

B4X:
'Activity module
Sub Process_Globals
   'These global variables will be declared once when the application starts.
   'These variables can be accessed from all modules.
   Dim MediaPlayer1 As MediaPlayer

End Sub

Sub Globals
   'These global variables will be redeclared each time the activity is created.
   'These variables can only be accessed from this module.

End Sub

Sub Activity_Create(FirstTime As Boolean)
   Activity.LoadLayout("sairamdosite2")
   
End Sub



Sub SetaEsquerdaButton1_Click
      Mediaplayer1.Initialize
      MediaPlayer1.Load(File.DirAssets, "Click1.wav")
      MediaPlayer1.Play
        
      Activity.Finish
   
End Sub

Sub SetaDireitaButton1_Click
      Mediaplayer1.Initialize
      MediaPlayer1.Load(File.DirAssets, "Click1.wav")
      MediaPlayer1.Play
        
'      StartActivity(SairamdoSite3)
   
End Sub

Sub SetaPrincipalButton1_Click
      Mediaplayer1.Initialize
      MediaPlayer1.Load(File.DirAssets, "Click1.wav")
      MediaPlayer1.Play
        
      Activity.Finish
      
   
End Sub


Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Legend:

I have put 3 buttons on the (SairamdoSite1) activity that have this info:

SetaEsquerdaButton1 -> Left Button
SetaDireitaButton1 -> Right Button
SetaPrincipalButton1 -> Main Page Button

the objective of the button's would be:

If I am on "SairamdoSite1" activity the button's would do this:

SetaEsquerdaButton1 -> Will finish the activity and go to my main activity
SetaDireitaButton1 -> Will go to my "SairamdoSite2" activity
SetaPrincipalButton1 -> Will finish the activity and go to my main activity

it works as I intended to work but,

If I am on "SairamdoSite2" activity the button's would do this:

SetaEsquerdaButton1 -> Will finish the activity and go to my "SairamdoSite1" activity
SetaDireitaButton1 -> Will go to my "SairamdoSite3" activity (That is commented, not active yet)
SetaPrincipalButton1 -> Will finish the activity and go to my main activity (In here is where it resides my big problem, if I finish this activity, it will go to the "SairamdoSite1" activity and not the "Main" activity that I want the effect to be.

If instead of:

Activity.Finish

I put

StartActivity(Main)

it will not finish my "SairamdoSite2" activity, after being in the "Main" I press the "Exit application Button" that I have there pointing out to a:


B4X:
Sub SairButton1_Click
      Mediaplayer1.Initialize
      MediaPlayer1.Load(File.DirAssets, "Click1.wav")
      MediaPlayer1.Play
  
   
      If Msgbox2("Deseja sair da aplicação?", "", "Sim", "", "Não", Null) = DialogResponse.POSITIVE Then

      
      Activity.Finish
      
    End If
  

End Sub

This would finish the Main activity but will open my earlier activity the "SairamdoSite2" Activity :(, and not exit the entire program as I want it :(

If I put "ExitApplication" instead of "Activity.Finish" it will go to my "SairamdoSite2" Activity and crash the program :(

Can anyone help me out to solve this problem?, I really would like to have this buttons in my application, the left button to bring me back to the previous activity, the right button to take me to the next activity, and "a main Button" to anywhere I am on my application pressing that button would finish whatever activity I am on and put me back in the Main activity.

Is this possible or I am asking for some impossible thing :(, thanks in advance, help would really be appreciated. :sign0085:

Joel :BangHead:
 
Last edited:

margret

Well-Known Member
Licensed User
Longtime User
3 Activities

If I understand you right, by looking at your code. You can have all three activities running at the same time. If you wish to finish each and return to the main activity, I would call activity one and when finished it returns to main. Then call activity two from main. When it is finished you will return to the main activity.

1..If you must have activity 1 call activity 2 and you wish activity two to return to the main, you must finish activity 2 and then finish activity 1.

2..If you are ok to call either 1 or 2 from the main, then remove any option to call 2 from 1 or to call 1 from two. Otherwise you may have to write some flags to a file and evaluate the status upon return.

Please let us know if you need to follow option 1 above or if option 2 will work.

You could also leave your code just as is but write a flag to a datafile when you finish the Main activity. In the other activities Resume code, check the state of this file, and if Main is finished, call Activity.Finish in the current activity from Activity_Resume. So write some file when you start the Main activity and erase it when you finish the Main activity. In the other two Activities, in their Activity_Resume, check for this file and if it DOES NOT exist, finish those activites also.

Thanks,

Margret
 
Last edited:
Upvote 0
Top