Android Question "Unfortunately, (App) has stopped" after apps list swipe

Javier Alonso

Member
Licensed User
Longtime User
Hi,

I have an app with several services: FirebaseMessaging, an SMS listener, a batch downloader and a batch ftp, none of them running in foreground. If I remove my app from the running apps list, I get after a few seconds the message "Unfortunately, (App) has stopped", and I get it twice. If Firebasemessaging is running as foreground, the message doesn't show, I suppose because the service does not stop.

How can I access the device logs or look for errors in any other way in Release mode? Because in Debug mode I cannot simply swipe the app, the debugger stops.

Thks
 

techknight

Well-Known Member
Licensed User
Longtime User
You will have to get a dump of the logcat and thumb through it to figure out what caused it. Any time you swipe to close the app it should fire Activity_Pause Userclosed = false, and from that event you need to unload all your services associated with the app and its links to the Activity. If the running services arnt stopped, and if they contain code that links back to the now not loaded "Activity" it will crash.
 
Upvote 0

Javier Alonso

Member
Licensed User
Longtime User
Thank you, techknight. I finaly managed to get the crash log uploading the app to the Play Store (in beta), installing it on my device and sending the crash report.

The bug had to do with Firebase notifications, which I had implemented as a FirebaseMessaging Sticky service, which was relaunched a few seconds after the swipe. The error was "java.lang.RuntimeException: Object should first be initialized (Intent)", and the solution was to check the initialization:

B4X:
Sub Service_Create
    fm.Initialize("fm")
End Sub

Sub Service_Start (StartingIntent As Intent)

    If StartingIntent.IsInitialized And fm.HandleIntent(StartingIntent) Then Return
...
 
Upvote 0
Top