Progmatically go to Home Screen

Omar

Member
Licensed User
Longtime User
Hello,

I was wondering if anyone knows of a way to progmatically go to the Home Screen or App screen.

Is there any way to do this?

Thank you.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
You can call Activity.Finish to close the current activity and return to the previous one or home screen.
You can show the home screen with this code:
B4X:
    Dim i As Intent
    i.Initialize(i.ACTION_MAIN, "")
    i.AddCategory("android.intent.category.HOME")
    i.Flags = 0x10000000
    StartActivity(i)
 
Upvote 0

Omar

Member
Licensed User
Longtime User
You can call Activity.Finish to close the current activity and return to the previous one or home screen.
You can show the home screen with this code:
B4X:
    Dim i As Intent
    i.Initialize(i.ACTION_MAIN, "")
    i.AddCategory("android.intent.category.HOME")
    i.Flags = 0x10000000
    StartActivity(i)

Thanks very much Erel.

Really appreciate your help with this, its working perfectly.

Just another quick related question, is it possible to trigger this in the background so that when the application is exited by the user the Home Screen is displayed at that time.

The code as is, pauses the application and goes directly to the home screen.
 
Upvote 0

Omar

Member
Licensed User
Longtime User
Thanks Erel :sign0188:

Actually I was just working on something and did not want the activity to close, but it appears that even with Keycode capture enabled the activity still pauses.

I am using the following code for capturing:

B4X:
Sub Activity_KeyPress (KeyCode As Int) As Boolean
   If KeyCode = KeyCodes.KEYCODE_BACK Then   
      Return True
   End If
End Sub
 
Upvote 0

Robert Valentino

Well-Known Member
Licensed User
Longtime User
You can call Activity.Finish to close the current activity and return to the previous one or home screen.
You can show the home screen with this code:
B4X:
    Dim i As Intent
    i.Initialize(i.ACTION_MAIN, "")
    i.AddCategory("android.intent.category.HOME")
    i.Flags = 0x10000000
    StartActivity(i)

I was going to post this as a new questions but feel it is just an continuation of the above.

Tried this code and it kind of works.
If there are multiple pages to the home screen sometimes it returns to the second page.

Is there a way to force it to the first page?

BobVal
 
Upvote 0
Top