Android Question Dialog run from service

invocker

Active Member
I need a dialog run from service with 2 button when user click yes show my app and hide dialog but when user click no hide dialog
the dialog want to be in the top of other app


if not possible then solve my issue hier
I create a custom layout dialog and show it when grab text . how can make it appear on top of other app when my app is resumed
I show my lay from service with B4XPages.ShowPage("msgbox1") and when user click yes button I hide my dialog and app
 
Solution
You need draw-Over permission

toby

Well-Known Member
Licensed User
Longtime User
1. I added a new service, svcMyApp, revelant code:
B4X:
Sub Service_Start (StartingIntent As Intent)
    B4XPages.ShowPage("My App")
    Service.StopAutomaticForeground 'Call this when the background task completes (if there is one)
End Sub


2. I added a new page, pgeMyApp, revelant code:
New page pgeMyApp code:
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    'load the layout to Root
    Root.LoadLayout("myapp")
    
    Dim sf As Object = xui.Msgbox2Async("Show My App?", "confirmation", "Yes", "Cancel", "No", Null)
    Wait For (sf) Msgbox_Result (Result As Int)
    If Result = xui.DialogResponse_Positive Then
        'Log("Deleted!!!")
        B4XPages.ShowPage("My App")
    Else
        'B4XPages.ShowPageAndRemovePreviousPages("MainPage")
        B4XPages.ClosePage(Me)   
    End If
End Sub

3. add following code to the MainPage:
B4X:
Sub Class_Globals
    Private Root As B4XView
    Private xui As XUI
    Public pageMyApp As pgeMyApp
End Sub

Public Sub Initialize
    B4XPages.GetManager.LogEvents = True
End Sub

'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
    pageMyApp.Initialize
    B4XPages.AddPage("My App", pageMyApp)
End Sub

Private Sub B4XPage_Appear
    
End Sub
'You can see the list of page related events in the B4XPagesManager object. The event name is B4XPage.

Private Sub Button1_Click
    'xui.MsgboxAsync("Hello world!", "B4X")
    StartService(svcStartMyApp)
End Sub

How to test it
1. Run the app (the attached project) and the main page will appear
2. Tap the Click button and the svcMyApp will cause the Dialog to apear.
3. Tap Yes, you'll see the MyApp page
4. Tap No, you'll be taken back the main page.

It works for me at least.
 

Attachments

  • showDialogFromService.zip
    16.6 KB · Views: 62
Upvote 0

invocker

Active Member
thank's mr Toby it not what I need ,I think that I d'ont explain it verry well so I explain again:

My app Grab text from clipboard If my app is in background and user copy link from any other programme like facebook for example my app grab this text and show dialog on top off facebook that what i need i hope you understand my question
 
Upvote 0

toby

Well-Known Member
Licensed User
Longtime User
You need draw-Over permission
 
Upvote 1
Solution
Top