I want to run my Android service(real-time notification service) after application installed and force it to work even application closed. This service responsible for listening my real-time notification server, when notification received I create Android notification and maybe run my app, if it is closed. I assume that my way is not correct for this case and there is another way working with real-time notification. I will be grateful if you give some link or a small explanation.
the better approach to listening my real-time notification server, you've to use GCM. here you can start reading about GCM. and if you want to implement it yourself you have to write a service yourself. ex:
public class ListenerService extends Service{
@Override
public void onStartCommand(Intent intent, int flags, int startId){
return START_STICKY; //this will restart your service even though the system kills
}
// you can write other listener service method inside the service
}
but still I recommend you to use GCM or other cloud messaging services instead of writing your own.