Android Question App Crash Android 6.0 and Firebase Messaging

iCAB

Well-Known Member
Licensed User
Longtime User
Hi All

I have an app that runs no problem on Android 5 or below and but when I tried on 6.0, the app started crashing (restarting on its own).

I narrowed the issue down to a code in my Firebase messaging Service (which gets started from the starter service)


B4X:
Public Sub UNSubscribeFromTopics( lstTopics As List)
  
    Dim i As Int  
  
    For i = 0 To lstTopics.Size - 1
        Log("FCM: unsubscribe: " & lstTopics.Get(i) )
Try      
            'Remove this line and the app runs no problem
        fm.UnsubscribeFromTopic(lstTopics.Get(i))
Catch
        GeneralLib.GL_Log(LastException)
End Try  
    Next
  
End Sub

The log doesn't show an error. Also the catch block is not executed.

Note that before calling the above code, I am calling the code below which works perfectly ok, showing that things are properly initialized


B4X:
Public Sub SubscribeToTopics( lstTopics As List)
  
    Dim i As Int  
  
    For i = 0 To lstTopics.Size - 1
        fm.SubscribeToTopic(lstTopics.Get(i))
    Next
      
    fm.SubscribeToTopic("general") 
  
    Dim cTokenID As String = fm.Token
    SaveToken( cTokenID )

 
End Sub


Any help is greatly appreciated
 
Last edited:

iCAB

Well-Known Member
Licensed User
Longtime User
Applications do not restart when they crash. You should see a message saying that the application has crashed.
Have you customized Application_Error in the starter service?

I am calling it an application crash because of its behavior, but it is not a true application crash. Here is a bit more info.

Below is the application flow:

Starter Service (Firebase messaging service is started in here)
Open Splash Screen Activity
Open login Screen Activity
User logs in
Open Main Menu Activity
Open apickupanddropoff (This activity calls the sub causing the issue)


This is what I see in the log
** Service (pushservice) Start **
** Activity (apickupanddropoff) Pause, UserClosed = false **
Killing previous instance (asplash).
** Activity (asplash) Create, isFirst = false **

Now the application looks like as if it is restarting.

If I remove the line below, everything works fine.

B4X:
fm.UnsubscribeFromTopic(lstTopics.Get(i)


Note that I am not facing the issue with earlier Android versions

Thanks in advance
 
Upvote 0

iCAB

Well-Known Member
Licensed User
Longtime User
Must be something with (other code in) your app. Here no problems with any version. Maybe your list entry is empty.

Hi KMatle

if you check the code in the first post, I added
B4X:
Log("FCM: unsubscribe: " & lstTopics.Get(i) )
to make sure that the list is not empty.

I should probably add that I tried the code by hard coding topics just in case, but I got the same results.

Also as I mentioned, the code runs perfectly on 5.0.2 and below
 
Last edited:
Upvote 0

iCAB

Well-Known Member
Licensed User
Longtime User
Try to reproduce it in a small project. I don't think that it is related to the call to UnsubscribeFromTopic.

Hi Erel

This is what I have done so far
I took the sample camera project and I added Firebase Messaging to it,
The problem doesn't happen.


Now coming back to my project. To isolate the issue. I declared fm as a public in a global code module

B4X:
Public fm As FirebaseMessaging

I removed all calls that interact with Subscribe/unsubscribe and I put a breakpoint in the old code just in case .
I created a simple Sub that can be called from anywhere

B4X:
Sub FCM_Subscribe()
    GC.fm.UnsubscribeFromTopic("general")
End Sub

I added the call to the above sub, in an activity that does nothing on its own (meaning nothing happening unless the user does something).
As soon as I click the button that executes the above Sub, I get the issue (Release or Debug mode)

I need some help as I am getting ready to release the app.
Is there anything I can do that can help you capture a log or any info that can help troubleshoot the issue?

Thanks again
 
Upvote 0

iCAB

Well-Known Member
Licensed User
Longtime User
Hi All,

I just thought to share my findings with you.

The tablet that I had the issue with, is a Samsung TAB E, running Android 6.0.1

The interesting part that the default version of Google Play Services was an older one: Version 8.0.26

Updating Google Play Services to: 11.5.09 solved the issue for me.

Hopefully this will benefit someone
 
Upvote 0
Top