B4A Library SD: MenuClose

I had the need to create a menu when it is required to exit App from the Back button of the device but also from the home button.

So I have to create something similar to closing the device.
Here is my new office.

SD_MenuClose

Author:
Star-Dust
Version: 0.05
  • MenuClose
    • Functions:
      • Class_Globals As String
      • ExitApplication2 As String
        Close the application and connected services
      • Initialize (BackgroundColor As Int, TextColor As Int) As String
        Initializes the object. You can add parameters to this method if needed.
        <code> MenuClose.Initialize(Colors.ARGB(200,150,150,150),Colors.White) </code>
      • IsInitialized As Boolean
        Verifica se l'oggetto sia stato inizializzato.

ezgif.com-crop.gif


use:
B4X:
Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("Layout1")

End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub Activity_KeyPress (KeyCode As Int) As Boolean 'Return True to consume the event
    If KeyCode=KeyCodes.KEYCODE_BACK Then
        Dim MC As MenuClose
        MC.Initialize
        Return True
    End If
 
    Return False
End Sub

  • 1.04
    • Added BackgroundColor parameter
  • 1.05
    • Added TextColor parameter
 

Attachments

  • sampleMenuClose.zip
    9.3 KB · Views: 227
  • SD_MenuClose 0.05.zip
    4.8 KB · Views: 228
Last edited:

johndb

Active Member
Licensed User
Longtime User
The SD_MenuClose.zip link appears to be broken.

EDIT: Works now ... thanls!
 

Erel

B4X founder
Staff member
Licensed User
Longtime User

Star-Dust

Expert
Licensed User
Longtime User
It depends on how the app is closed. If it is closed with ExitApplication then it is indeed not recommended.

If you are targeting Android 4.1+ then you can use this code to finish all activities: https://www.b4x.com/android/forum/threads/exitapplication-vs-activity-finish.79548/#post-503759
Thanks Erel of the clarification, and hanging on it, I thought it was a good idea to make the closing operation as a public method in release 0.02

Instead of ExitApplication (with the issues we know) we could use MenuClose.ExitApplication2
 

LucaMs

Expert
Licensed User
Longtime User
If you are targeting Android 4.1+ then you can use this code to finish all activities: https://www.b4x.com/android/forum/threads/exitapplication-vs-activity-finish.79548/#post-503759
I used this code:
B4X:
' Main
Public Sub CloseApp
    Activity.Finish
    Starter.CloseApp = True
    StopService(Starter)
End Sub

B4X:
' Starter
Public CloseApp As Boolean


Sub Service_Destroy   If CloseApp Then
      StopService(srvComm)
      ExitApplication
   End If
End Sub

but this code would no longer work with b4a 8.30; QUIZ: guess why ;)


I had not read that "trick", Erel (... jo.RunMethod("finishAffinity", Null) ), thank you.
[I still need a solution for Android < 4.1 but "I have" time: before closing my app I have to start it :D]
 

incendio

Well-Known Member
Licensed User
Longtime User
Thanks Erel of the clarification, and hanging on it, I thought it was a good idea to make the closing operation as a public method in release 0.02

Instead of ExitApplication (with the issues we know) we could use MenuClose.ExitApplication2
Sorry for the OOT, but what issues with ExitApplication ?
 

Star-Dust

Expert
Licensed User
Longtime User

ddefrain

Member
Licensed User
Longtime User
I had the need to create a menu when it is required to exit App from the Back button of the device but also from the home button.

So I have to create something similar to closing the device.
Here is my new office.

SD_MenuClose

Author:
Star-Dust
Version: 0.03
  • MenuClose
    • Functions:
      • Class_Globals As String
      • Initialize As String
        Initializes the object. You can add parameters to this method if needed.
      • ExitApplication2 As String
      • IsInitialized As Boolean
        Verifica se l'oggetto sia stato inizializzato.

View attachment 68505

use:
B4X:
Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("Layout1")

End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub Activity_KeyPress (KeyCode As Int) As Boolean 'Return True to consume the event
    If KeyCode=KeyCodes.KEYCODE_BACK Then
        Dim MC As MenuClose
        MC.Initialize
        Return True
    End If
 
    Return False
End Sub

Hello, Thanks for the Lib.
Is it possible to change the background color and the icon colors?

Thank's in advance
Best Regards!
 

Star-Dust

Expert
Licensed User
Longtime User
I updated to version 1.04 which allows you to change the background
 
Last edited:
Top