Android Question Need to restart the application to receive the notification

qey

Member
Hi I need help, ive one application where there is an update, the user will receive a notification. I tested the app, i only receive the notification once i restart the apps. Is there any idea? btw im using oppo Android Version 8.1.0. Attach here the main code from the application. Is there anything wrong here ?

Main:
Sub Activity_Resume
    Dim rp As RuntimePermissions
    rp.CheckAndRequest(rp.PERMISSION_READ_EXTERNAL_STORAGE)
    Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
    If Result = False Then
        ToastMessageShow("No permission!", True)
        Return
    End If
    
    rp.CheckAndRequest(rp.PERMISSION_WRITE_EXTERNAL_STORAGE)
    Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
    If Result = False Then
        ToastMessageShow("No permission!", True)
        Return
    End If
End Sub

Sub Activity_Pause (UserClosed As Boolean)
    B4XPages.Delegate.Activity_Pause
End Sub

Sub Activity_PermissionResult (Permission As String, Result As Boolean)
    B4XPages.Delegate.Activity_PermissionResult(Permission, Result)
End Sub

Sub Create_Menu (Menu As Object)
    B4XPages.Delegate.Create_Menu(Menu)
    If Registered = True Then NotificationHandler
End Sub

#if Java
public boolean _onCreateOptionsMenu(android.view.Menu menu) {
     processBA.raiseEvent(null, "create_menu", menu);
     return true;
    
}
#End If
#End Region
Sub ParseNotification(json As String) As String
    json = json.Replace($"\r\n"$,CRLF)
    Dim parser As JSONParser
    parser.Initialize(json)
    Dim jRoot As Map = parser.NextObject
    Dim Status As String = jRoot.Get("Status")
    If Status.EqualsIgnoreCase("1") Then
        Dim notifications As List = jRoot.Get("Notifications")
        For Each colline As Map In notifications
            CallSubDelayed2(FirebaseMessaging, "performAction",UTILS.initNotification(colline.Get("Description"),"",colline.Get("Transid"),colline.Get("Recid")))
        Next
    End If
    Return Status
End Sub
Sub restartApp
    If restartOk Then
        restartOk = False
        Activity.Finish
        StartActivity(Me)
    End If
End Sub
Public Sub GetStartingIntent As Intent
    Return Activity.GetStartingIntent
End Sub
Sub NotificationHandler
    If FirstStart = True Then
        CallSubDelayed(MobileAPI, "NotificationDownload")
        FirstStart = False
        Return
    End If
'    Dim in As Intent = B4XPages.GetNativeParent(Me).GetStartingIntent
    Dim in As Intent = Activity.GetStartingIntent
    If in.IsInitialized Then
        Dim intentExtra As String
        'Log("IsInitialized")
        If in.HasExtra("Notification_Tag") Then
            intentExtra = in.GetExtra("Notification_Tag")
            'Log("XTRA="&intentExtra)
            Dim jp As JSONParser
            jp.Initialize(intentExtra)
            Dim jRoot As Map = jp.NextObject
            Dim opt As String = jRoot.Get("Option")
            'Dim val As String = root.Get("Value")
            Dim nId As String = jRoot.Get("id")
            'Log(opt & " | " & val & " | " & nId)
            Select opt
                Case "DeleteApps" :
                    CallSubDelayed(MobileAPI, "NotificationDownload") 'CallSubDelayed3(MobileAPI, "JobsDownload",val,nId)
                Case "CustomerInfo" :
                    CallSubDelayed(MobileAPI, "Update")
            End Select
            Dim n As Notification
            n.Initialize
            n.Cancel(nId)
        End If
    End If
End Sub
 
Top