Exit application.

magarcan

Active Member
Licensed User
Longtime User
Are there any way to force exit mi application on back button pressed? I want my app exit every time instead of be kept in memory.

Thanks!!!
 

timo

Active Member
Licensed User
Longtime User
Activity.Finish lets the App stay resident. Maybe ExitApplication is better, but I don't thik it exists something stronger. As I've eard, Activity.Finish is anyway more in Android's phylosophy.
 
Upvote 0

timo

Active Member
Licensed User
Longtime User
...but I don't know how to detect Back button.

B4X:
Sub Activity_KeyPress (KeyCode As Int) As Boolean 

   Dim Ans As Int
   Dim x As String
   
   If KeyCode= KeyCodes.KEYCODE_BACK Then
   
      x = "Quit application?"
      Ans = Msgbox2(x, "AppName", "YES", "", "NO", Null)
      
      If Ans = DialogResponse.NEGATIVE Then
         
         Return True 
         
      Else
      
      Activity.Finish 
      
      End If
      
   End If
   
End Sub
 
Upvote 0

pluton

Active Member
Licensed User
Longtime User
The idea is call ExitApplication instead of Activity.Finish but I don't know how to detect Back button.

Maybe like this:

B4X:
Sub Activity_KeyPress (KeyCode As Int) As Boolean 'return true if you want to consume the event
    If KeyCode = KeyCodes.KEYCODE_BACK Then
        If Msgbox2("Do you want to close?", "", "Yes", "Cancel", "No", Null) = DialogResponse.POSITIVE Then
          '  Return False
 ExitApplication 'App is exiting
        Else
            Return True
        End If
    End If
End Sub
 
Last edited:
Upvote 0

timo

Active Member
Licensed User
Longtime User
I find that calling Activity.Finish AND ExitApplication makes sure it closes

Apparently. Try this and manage the end of App as you prefer, then reopen the App.

B4X:
Sub Activity_Create(FirstTime As Boolean)

If FirstTime Then
   
   Msgbox("First Time","")
   
Else
   
   Msgbox("Second Time: I was resident in memory","")
   
End If

End Sub
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
Are there any way to force exit mi application on back button pressed? I want my app exit every time instead of be kept in memory.

Thanks!!!

There is a special sub, called Activity_Pause (UserClosed As Boolean), wich is called once when app start ( OS feature ), and every time the app is sent to background, either by the start of another app, or by the user pressing the backbutton.
In the last case, the UserClosed boolean will return true, so you can ue it to check if it was by that acton that the app was paused..
Something like:

If UserClosed then Activity.Finish
 
Upvote 0

wm.chatman

Well-Known Member
Licensed User
Longtime User
I am using:

Sub Activity_KeyPress (KeyCode AsInt) AsBoolean
Dim Ans AsIntDim x AsString
If KeyCode= KeyCodes.KEYCODE_BACK Then

x = "Quit application?"
Ans = Msgbox2(x, "AppName", "YES", "", "NO", Null)
If Ans = DialogResponse.NEGATIVE Then
ReturnTrue
Else

Activity.Finish
EndIf
EndIf
End Sub

how do I place a small img before the x = "Quit application?" that is located in the Files Folder?
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Replace the null as last parameter to and icon... See contencthelp of MsGBox2

B4X:
result = Msgbox2("This is the message", "This is the title", "Good", "", "Bad", LoadBitmap(File.DirAssets, "smiley.gif"))
 
Upvote 0

wm.chatman

Well-Known Member
Licensed User
Longtime User
Img showing now when Exit App. How would I get this right with the bellow code

cat1.AddList("notifysound", "On/Off Sound", "Turn the Notification Sound On or Off", "", _
Array As String("On", "Off")

LoadBitmap(File.DirAssets, "android48.png")) I cant get working here. What is wrong?
 
Upvote 0

wm.chatman

Well-Known Member
Licensed User
Longtime User
oh just show a small png. like with the msg box in above post.

I got this:
cat1.AddList("notifysound", "On/Off Sound", "Turn the Notification Sound On or Off", "", _
Array As String("On", "Off")

LoadBitmap(File.DirAssets, "android48.png"))

and need to show png before "On/Off Sound"

I cant figure where to write > LoadBitmap(File.DirAssets, "android48.png"<
 
Upvote 0

wm.chatman

Well-Known Member
Licensed User
Longtime User
Sub CreatePreferenceScreen 'preferenceactivity settings
screen.Initialize("Settings", "")
'create two categories
Dim cat1, cat2 As PreferenceCategory
cat1.Initialize("Settings")
'cat1.AddCheckBox("check1", "Checkbox1", "This is Checkbox1", True)
'cat1.AddCheckBox("check2", "Checkbox2", "This is Checkbox2", False)
'cat1.AddEditText("edit1", "EditText1", "This is EditText1", "")

'cat2.Initialize("Category 2")
cat1.AddList("list1", "Distance Measurement", "Miles or Kilometers", "", _
Array As String("Miles", "Kilometers"))

cat1.AddList("list2", "Distance to message popup", "Distance in meters from target location to message popup - longer distance in built up areas", "", _
Array As String("20", "30", "40", "50", "60","70"))

cat1.AddList("list3", "Message database time", "Main screen only - The update time for the Database of active messages on the main screen. Longer time easier on phone but does not affect accuracy", "", _
Array As String("20", "40", "60", "80", "100","150"))

cat1.AddList("notifysound", "On/Off Sound", "Turn the Notification Sound On or Off", "", _
Array As String("On", "Off")) 'LoadBitmap(File.DirAssets, "android48.png"))

'add the categories to the main screen
screen.AddPreferenceCategory(cat1)
'screen.AddPreferenceCategory(cat2)
End Sub
 
Upvote 0
Top