Android Question [B4xPages] [SOLVED] GoogleMap not initialized when "dead" app is opened from notification

Mashiane

Expert
Licensed User
Longtime User
Ola

I am receiving gps co-ordinates via FireBase and these show via notifications. The plan is, as soon as the notification is selected, a b4x page with GoogleMaps should be opened. This works well when the app is running. When the app is not running, after selecting the notification, the app is opened, the page to be opened gets opened, however google maps is not initialized.

B4X:
java.lang.RuntimeException: Object should first be initialized (GoogleMap).

How can I solve this?

A previous working google map project is here:

Thank you.

PS: I am using this example code to open another page via notification.

 

Mashiane

Expert
Licensed User
Longtime User
I can guess that you are trying to access the map before the Ready event.
Thanks, this gave me an idea and then I used the google map code to check that..

On Main

B4X:
Sub Activity_Resume
    LogColor("Main.Resume...", Colors.Magenta)
    B4XPages.Delegate.Activity_Resume
    B4XPages.MainPage.ActivityResume
End Sub

On B4XMainPage

B4X:
'when a notification is clicked
Sub ActivityResume
    LogColor("MainPage.Activity_Resume...", xui.Color_Magenta)  
    Dim in As Intent = B4XPages.GetNativeParent(Me).GetStartingIntent
    If in.IsInitialized And in <> LastIntent Then
        LastIntent = in
        If in.HasExtra("Notification_Tag") Then
            Dim stag As String = in.GetExtra("Notification_Tag")
            modX.FromNotification = True
            modX.NotificationPosition = modAgriTrax.Json2Map(stag)
            Dim smsgtype As String = modX.NotificationPosition.Get("msgtype")
            Select Case smsgtype
            Case "registration"
                B4XPages.ShowPage("MainPage")
            Case "08", "09", "03", "04"
                If myloc.gmap.IsInitialized = False Then
                    Wait For (myloc.InitializeMap) Complete (Success As Boolean)
                    myloc.MapReady = Success
                    If myloc.MapReady Then
                        myloc.gmap.AddMarker(0, 0, "Center")
                    End If
                End If  
                B4XPages.ShowPage("myloc")
            End Select
        End If
    End If
End Sub
 
Upvote 0
Top