android - How to know when service is started after calling startService() method to send otto event? -


i have alarmreceiver(brodcastreceiver) starts downloadservice(service) after check if service not running state

context.startdownloadserviceifnotrunning()// kotlin extension function check service state 

after line sending otto event started service

busstation.getbus().post(downloadevent())  // line fired before start of service 

but download service not receiving event registerd event.

after debugging have found otto event firing before service starts therefore not receiving event

so there way know when android service started receive events otto

you can add parameter intent. how use parameters, not otto?

intent serviceintent = new intent(this,downloadservice.class);  serviceintent.putextra("key", "value"); startservice(serviceintent); 

and, onstart of service, can use parameters.

@override public void onstart(intent intent, int startid) {     super.onstart(intent, startid);     bundle extras = intent.getextras();      if(extras == null) {         //     } else {         string value = (string) extras.get("key");         if (value.equals("value")) {             // same thing want otto event.         }     } } 


edited: if event not time-critical one, can delay event.

new handler().postdelayed(new runnable() {     @override     public void run() {         busstation.getbus().post(downloadevent());     } },1000); 

otherwise, need make own message queue.


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -