Titanium JIRA Archive
Appcelerator Community (AC)

[AC-6185] Can't run background services w/ foreground notification on Android

GitHub Issuen/a
TypeBug
Priorityn/a
StatusResolved
ResolutionDone
Resolution Date2019-05-08T23:41:34.000+0000
Affected Version/sn/a
Fix Version/sn/a
Componentsn/a
Labelsn/a
Reporterjon kravetz
AssigneeShak Hossain
Created2019-03-29T13:33:46.000+0000
Updated2019-05-08T23:41:35.000+0000

Description

This is related to a discussion on TIMOB-26538. Background services w/ a foreground notification no longer work when exiting the app on Android. Somehow design felt it was appropriate to completely stop and remove all android services and broadcast receivers upon closing the app. This breaks our app and will break any app that relies on background services to work even when the app is completely closed (not in background). This scenario is what foreground notifications were designed for in Android API 26, and it should work as expected. Steps to reproduce: 1) Create an android app. 2) Create an android service. 3) Create a foreground notification for that android service. 4) Swipe closed the app. Expected behavior: The service(s) should continue to run. Actual behavior: The service does not run. Upon restarting the app, user may see some error messages about the service that can't run.

Comments

  1. Joshua Quick 2019-03-30

    This is not a bug. We intentionally made a breaking-change in Titanium 8.0.0 to auto-close Titanium services when the UI has been exited for the reasons mentioned in [TIMOB-26538]. So, yes, swipe-exiting the app via Android's recents-list will exit the UI and thus destroy all of its Titanium services. I think this behavior is fine. Titanium as a product is tightly bound to the UI on all platforms it supports. If you absolutely *need* a service to run independently of the UI, then the solution is to write it natively in Java. That way the service's lifetime is no longer dictated by the lifetime of the JavaScript runtime.
  2. jon kravetz 2019-04-01

    What is the point of including functionality for foreground notifications if Titanium does not allow their appropriate usage? Foreground notifications are to be displayed so that android services can run even when the app is completely closed. They are not neccessary when the app is backgrounded. Up until this point, we've always been able to do pretty much everything in Titanium that we could do in native. We have been able to use android services with the app completely closed for years. Why all of a sudden this change? It feels like a bug to us. We've been using this functionality for years and now it's broken. It makes no sense to include code to incorporate foreground notifications when we can not run background services indepedently of the application UI (like we've been doing for years). I get that you may have your reasoning, but this makes absolutely no sense to us.
  3. Joshua Quick 2019-04-02

    I've already answered this. You and I are talking in circles. While the old behavior may have worked out for you, for the vast majority of Titanium users it was not. The old Titanium service handling had a major design issue which I've documented in that ticket. It was causing app relaunch issues for the majority of app developers. We can't "fix" a design issue; the design has to change. Titanium as a product is tightly bound to the UI anyways. The first script that gets executed, the "app.js", wants to launch the UI. This is the design of the product on all platforms. Only Android broke the rules so-to-speak when it came to services/broadcast-receivers and it should have never have been implemented this way to begin with. The answer should have always been "implement it natively" when it came to backgrounded services without UI. We've closed this design hole as of 8.0.0. For the majority of Titanium app devs I've worked with, they're services were already tightly bound to the UI anyways. I can understand how this might upset you, but this is how it has to be moving forward. My answer is you need to implement the service natively.
  4. jon kravetz 2019-04-02

    Okay. Sorry for the frustration. I guess we could still show the foreground notification using titanium. Could you point me in the direction of a sample project and or example of how this might work? Can i still include the services in the tiapp.xml if they are native? What's the best documentation or example you have on this?
  5. Joshua Quick 2019-04-03

    Sure. Android services are pretty easy to implement. If I can't find an existing 3rd party one, then I'll see about coding up a module for you to customize.
  6. Sharif AbuDarda 2019-04-09

    Hello [~jonkravetz], Were you able to find 3rd party foreground notification module? Can you follow us on Joshua's comment above? Let us know if you need more assistance. Thanks.
  7. Joshua Quick 2019-04-09

    This is something I'll have to put together. (I haven't forgotten.) I'll likely attach the solution to [TIMOB-26538] for better visibility.
  8. Sharif AbuDarda 2019-05-08

    Hello [~jonkravetz], Please follow the other ticket which is resolved now. Try the latest module in there. Thanks.

JSON Source