Note that there are some explanatory texts on larger screens.

plurals
  1. POMultiple activities binding to a service
    primarykey
    data
    text
    <p>I have a service component (common task for all my apps), which can be invoked by any of the apps. I am trying to access the service object from the all activities, I noticed that the one which created the service [startService(intent)] has the right informaion. But rest does not get the informaion needed. My Code is as below:</p> <pre><code>// Activity.java public void onCreate(Bundle savedInstanceState) { ... Intent intent = new Intent (this.context, Service.class) ; this.context.startService(intent) ; this.context.bindService(intent, this, Context.BIND_AUTO_CREATE) ; ... String result = serviceObj.getData() ; } public void onServiceConnected(ComponentName name, IBinder service) { serviceObj = ((Service.LocalBinder)service).getService(); timer.scheduleAtFixedRate(task, 5000, 60000 ) ; } // Service.java private final IBinder mBinder = new LocalBinder(); public class LocalBinder extends Binder { Service getService() { return Service.this; } } public void onCreate() { super.onCreate(); context = getApplicationContext() ; } public void onStart( Intent intent, int startId ) { ... some processing is done here... } public IBinder onBind(Intent intent) { return mBinder; } </code></pre> <p>If I invoke startService(intent). it creates a new service and runs in parallel to the other service.</p> <p>If I don't invoke startService(intent), serviceObj.getData() retuns null value.</p> <p>Can any one enlighten me where have I gone wrong.</p> <p>Any kind of pointer will be very useful..</p> <p>Thanks and regards, Vinay</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload