How to run the Android phone Android application in the background (after closing the application)?

I used the system alert plugin from github ( https://github.com/saileshmittal/phonegap-system-notification-plugin ) for android phonegap. I used this code in my index. HTML

My code is:

document.addEventListener("deviceready", onDeviceReady, false); function onDeviceReady() { var not_title = 'Message'; var not_text = 'Zou dit werken?'; var not_tText = 'Message'; navigator.systemNotification.onBackground(); navigator.systemNotification.onForeground(); navigator.systemNotification.createStatusBarNotification(not_title, not_text, not_tText); } 

I got a notification icon both in the foreground and in the background. But you can run the whole application to run in the background when a button is pressed in the application and call my wcf services. I also need to get a warning even when running in the background. How to do it?

navigator.systemNotification.onBackground() : this line launches the application in the background, and not another, only to display a notification after closing the application.

please help me, thanks in advance.

+6
source share
2 answers

According to the documentation on telephone records, you cannot run applications in the background, js cannot continue to work. Reason notifications may work because they use their own system to send notifications.

To make processes run in the background, you need to create a plugin that uses native os.

+1
source

I made an Android application with PhoneGap, and when I press the home button, my application remains in the background (my last test lasts more than 1 hour). But when I launch another application, the Android OS kills my application.

To enable this behavior, you need to add android permission:

<uses-permission android:name="android.permission.WAKE_LOCK" /> to your manifest

and you also need to add:

<preference name="exit-on-suspend" value="false" /> in config.xml in the res/xml folder

Hope this post helps you :)

+4
source

Source: https://habr.com/ru/post/908967/


All Articles