Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

startForeground & Keeping WebViews Alive #17

Open
lylepratt opened this issue Oct 11, 2014 · 11 comments
Open

startForeground & Keeping WebViews Alive #17

lylepratt opened this issue Oct 11, 2014 · 11 comments
Assignees
Milestone

Comments

@lylepratt
Copy link

I'm interested in using this plugin to create a "dummy" service as described in this StackOverflow post in order to prevent a WebView from being killed (so javascript continues to execute):
http://stackoverflow.com/questions/12226703/backgrounding-phonegap-and-the-relationship-between-activity-process-and-servi

It looks like in order for the above to work, I have to use startForeground which requires onStartCommand. Basically my purpose for this is because I'm using Sip.JS & WebRTC to create a VoIP phone and need to be able to continue to receive calls in the background (so can't have the webview getting killed).

It looks like all I need to do is implement onStartCommand and startForeground to accomplish this, but I was curious if you had any additional thoughts or experience on keeping WebViews alive.

Thanks,
Lyle

@lylepratt
Copy link
Author

@lylepratt
Copy link
Author

@Red-Folder I created a plugin based on your sample that does what I describe above:
https://github.com/BetterVoice/bv-bgs-foreground

Works great.

@Red-Folder
Copy link
Owner

Good job. Well done.

Have you thought about merging this code into the bgs-core repository?

@Red-Folder
Copy link
Owner

Enhancement: Add startForeground as an option.

Some notes on startForeground here -> http://developer.android.com/reference/android/app/Service.html#onStart(android.content.Intent,int)

Note that I don't specifically think it is a valid scenario to use the service to keep the app open - that's just not how the Android lifecycle is designed (from my understanding)

@Red-Folder Red-Folder added this to the April 2015 milestone Mar 17, 2015
@Red-Folder Red-Folder self-assigned this Mar 17, 2015
@lylepratt
Copy link
Author

I've been using startForeground as a method to keep the app alive for a few months now. You're correct that it is not designed for keeping the app open, but it does decrease the likelyhood that the app will be killed due to memory pressure because the OS assumes the user is using the functionality actively in the foreground.

My particular use case is for a VoIP app that uses webRTC. I display a notification that shows the current VoIP status, call status, etc, so it works nicely for me.

@Red-Folder
Copy link
Owner

Merging in of old repo issue -> Red-Folder/Cordova-Plugin-BackgroundService#40

@Red-Folder
Copy link
Owner

(Notes to self)

For a custom Notification, see http://developer.android.com/guide/topics/ui/notifiers/notifications.html (scroll to the bottom and Custom Notification Layouts)

Probably best in first incarnation to follow Android standard Notification setup. Then an additional enhancement to look at custom.

Gut feel is that you wouldn't be able to include a webview into a custom notification (bit of a shame).

@charmingarpit
Copy link

@lylepratt On Galaxy S6 Edge, I don't know if it is a Samsung issue that even after creating a background service STICKY and acquiring the partial wakelock, the app once killed by the process manager never restarts. It restarts only once the phone is rebooted. The same does not happens on stock android though. Thanks to you for providing a "foreground" service option. After using this in combination with "partial wakelock" i have ensured that even on galaxy S6 edge the service keeps on running without getting killed.

@charmingarpit
Copy link

@lylepratt Also i would like to ask you, if there is any way to make the service run as a foreground service but without any notification on the notification area?

@lylepratt
Copy link
Author

I think the core requirement of a "foreground" service is that it HAS to
display a notification. Unfortunately it won't be possible to run the
process in the "foreground" without the notification.

Relevant stackoverflow post:
http://stackoverflow.com/questions/10962418/startforeground-without-showing-notification
On Jan 10, 2016 10:22 PM, "charmingarpit" notifications@github.com wrote:

@lylepratt https://github.com/lylepratt Also i would like to ask you,
if there is any way to make the service run as a foreground service but
without any notification on the notification area?


Reply to this email directly or view it on GitHub
#17 (comment).

@charmingarpit
Copy link

@lylepratt ok. thanks for the help. In my service I had to additionally take wakelock as described in Red-Folder/Cordova-Plugin-BackgroundService#52 by vista-54. However, I see that this is eating up a lot of battery. Is there any alternative?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants