I am looking to write an app that receives pushed alerts from a server. I found a couple of methods to do this.
Firebase Cloud Messaging (FCM) is the new version of GCM. FCM is a cross-platform messaging solution that allows you to send messages securely and for free. Inherits GCM's central infrastructure to deliver messages reliably on Android, iOS, Web (javascript), Unity and C ++.
As of April 10, 2018, Google has disapproved of GCM. The GCM server and client APIs are deprecated and will be removed on April 11, 2019. Google recommends migrating GCM applications to Firebase Cloud Messaging (FCM), which inherits the reliable and scalable GCM infrastructure.
Resource
Google's official answer is the Android Cloud to Device Messaging Framework (deprecated) Google Cloud Messaging(deprecated) Firebase Cloud Messaging
It will work on Android >= 2.2 (on phones that have the Play Store).
You can use Pusher
It's a hosted service that makes it super-easy to add real-time data and functionality to web and mobile applications.
Pusher offers libraries to integrate into all the main runtimes and frameworks.
PHP, Ruby, Python, Java, .NET, Go and Node
on the server
JavaScript, Objective-C (iOS) and Java (Android)
on the client.
There is a new open-source effort to develop a Java library for push notifications on Android based on the Meteor web server. You can check it out at the Deacon Project Blog, where you'll find links to Meteor and the project's GitHub repository. We need developers, so please spread the word!
I dont know if this is still useful. I achieved something like this with a java library at http://www.pushlets.com/
Althoug doing it in a service won't prevent android from shutting it down an killing the listener thread.
or....
3) Keep a connection to the server, send keep-alives every few minutes, and the server can push messages instantly. This is how Gmail, Google Talk, etc. works.