How to run app in background even if it is closed like whatsapp


#1

i need to run my app without launching my application like whatapp ,so i can receive message through socket and show count badge. i have tried background mode plugin but it didnt work,is there any way i can get message notification after i closed my app. i just want to show the message count in badge.


#2

I think the best way to do it is not running the app in background, but sending data as push notifications. Have a look: http://docs.ionic.io/docs/push-overview


#3

I thought about that but I still need to do this using the background service as opposed to push.


#4

thank u for the replay
is push notification works if app is not running


#5

i thought about background service but i think i have to write a plugin to do that


#6

@halukkaramete I think only under certain specific conditions you’d need a background service running. In this case you can use the background plugin (https://github.com/katzer/cordova-plugin-background-mode). I know it exists but I’ve never used it, and depending on the case you’d have to code your own plugin. Also I’m not sure if it is a good practice to keep the app running in the background (it can increase battery use and you can never be sure if and when the OS will close your app). Maybe some experts can help on this?

@georgeMathew yes, push notifications should work even if the app is not running. See http://stackoverflow.com/questions/11508613/how-does-push-notification-technology-work-on-android and https://developers.google.com/cloud-messaging/gcm.


#7

#8

I don’t understand what is the use of plugin you mentioned here power-management.what does it do?we want to run the service even though if the app is closed?


#9

when an app is in the background (minimized) or the device has its screnn turned off, the OS (android) might not ‘run’ continuously your app.

This plugin forces the OS to keep running your app (while keeping the screen off) so that all your processing (geolocation, calling webservices, having ‘timeouts’ trigger functions, etc…) continue when your phone is in your pocket with your app in the backgorund and the screen off.

(warning: while debugging via plugged USB wire, android will NOT put your app in sleep so you might think you dont need the power-management plugin. but if you really try your app unplugged in real world you will see.)


#10

i loved your ansewrs, and for background mode plugin what does it do? plz


#11

Hi med : please see https://github.com/boltex/cordova-plugin-powermanagement and read below in the readme there is more links to follow that explain a bit more.


#12

thnk u so much for your response, but i saw all your posts ang comment about this issue, i used your custom plugin, may be i found the issue, my app work fine when screen is turned off after +/- 3h, my smartphone disconnect from wifi then app doesn’t send request anymore :((((


#13

there is a way to force app to using wifi for long period and prevent android system from disconnecting from wifi after long period from time when screen is turned off


#14

@boltex can u give me your personnal email plz