Android Question App keeps coming to live after closed

Pedro Caldeira

Active Member
Licensed User
Longtime User
Hello All,
I work in a Software house that has a professional checklists app, in B4A, that I am maintaining and improving.
One of the problems that we have is that even after, closing all services, flushing the app, closing activities, exiting application and even using that javaobject code

B4X:
Dim jo As JavaObject
jo.InitializeContext
jo.RunMethod("finishAffinity", Null)

to exit the App, it keeps coming back to the tray and doesn't stop, using resources frome the equipament.
It only stops if I go to settings / Apps and force close it.
Can I force close it by code ?
I fon't know what else to do to close it, other than using an "hammer"
 

JohnC

Expert
Licensed User
Longtime User
Make sure:

1) None of your services are configured for StartAtBoot:
B4X:
#StartAtBoot: True

2) Make sure you are not calling StartServiceAt/Exact:
B4X:
StartServiceAt(xxx)

3) That there are no Static Intents defined in your manifest

4) That your app is not displaying any Notifications

5) That your app is not configured to receive any push messages
 
Upvote 0

JohnC

Expert
Licensed User
Longtime User
And if none of those apply, please feel free to post your apps code because a lot of us are actually having trouble preventing our apps from being killed by the OS (power savings, etc), so we would be very interested in your magical code!
 
Last edited:
Upvote 0

OliverA

Expert
Licensed User
Longtime User
Besides @JohnC's comment, please note, you trying to "forcefully" stop your application is actually just plain fighting Android. Android decides when to properly shut down your application. You are not 100% in control of your application's life cycle. And it makes sense. Android is lazy in shutting your application down. If it is an application that is used a lot, it makes sense. Why re-load the whole application (and use up precious battery resources), if most of it can just be kept alive until needed once more. Are you concerned about resource usage? Android will gladly kill your idle application if it needs to. Until then, it just does not bother and neither should you. Again, this should be taken with the thought in mind that you have made sure that your application is not actually still actively engaging with the device (as pointed out by @JohnC and @DonManfred).
 
Upvote 0

Pedro Caldeira

Active Member
Licensed User
Longtime User
You are probably using any Foregroundservice?

I am using Service.AutomaticForegroundMode = Service.AUTOMATIC_FOREGROUND_NEVER
But I use one service that starts at boot and several like that

B4X:
Sub Service_Start (StartingIntent As Intent)
   
    Service.StopAutomaticForeground
    isStarted = True
   
    If Not(globalVars.StopCommsCheck) Then
        StartServiceAt(Me, DateTime.Now + 15 * 1000, True)
        Log("Comms Check")
    End If
   
End Sub
 
Upvote 0

JohnC

Expert
Licensed User
Longtime User
This is the line that will keep restarting your app:
B4X:
StartServiceAt(Me, DateTime.Now + 15 * 1000, True)

You need to run CancelScheduledService to prevent it from restarting.
 
Upvote 0

Pedro Caldeira

Active Member
Licensed User
Longtime User

Thanks,
Going to try and Cancel all Scheduled services and then close the App
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…