Need code example on how to run an Android service forever in the background even when device sleeping, like Whatsapp?

NOTE: NOW THIS ANSWER IS ONLY VALID FOR ANDROID 7 AND BELOW. SINCE ANDROID 8 GOOGLE HAS CHANGED HOW BACKGROUND TASKS ARE HANDLED Since I posted this question, I have implemented two different approaches to this solution into multiple apps. APPROACH 1 This extract is from an app where I use push notifications, which need … Read more

How to create a Service which continuously monitors app usage information?

As you wrote that the task is about monitoring 3-rd party applications, there is no solution other than periodically read a list of processes and detecting foreground process. You need a service for this. Unfortunately, Android does not provide means such as broadcast events for foreground process change. The task requires a lot of code … Read more

Android how do I wait until a service is actually connected?

How can I wait for ServiceConnection.onServiceConnected being called reliably? You don’t. You exit out of onCreate() (or wherever you are binding) and you put you “needs the connection established” code in onServiceConnected(). Are all the event handlers: Activity.onCreate, any View.onClickListener.onClick, ServiceConnection.onServiceConnected, etc. actually called in the same thread Yes. When exactly is ServiceConnection.onServiceConnected actually going … Read more

How to access service container in symfony2 global helper function (service)?

I assume that the first error (undefined property) happened before you added the property and the constructor. Then you got the second error. This other error means that your constructor expects to receive a Container object but it received nothing. This is because when you defined your service, you did not tell the Dependency Injection … Read more

What is the correct way to start a mongod service on linux / OS X?

Edit: you should now use brew services start mongodb, as in Gergo’s answer… When you install/upgrade mongodb, brew will tell you what to do: To have launchd start mongodb at login: ln -sfv /usr/local/opt/mongodb/*.plist ~/Library/LaunchAgents Then to load mongodb now: launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mongodb.plist Or, if you don’t want/need launchctl, you can just run: mongod It … Read more

tech