Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I don't know exactly what you want, but this is not the way to do it. It seems you're mixing up a lot of things. </p> <p>The tutorial itself is a bad example to my opinion, keeping a static reference to an activity in a service seems to me bad practice; you would use binding to bind your service to an activity, or if you don't want to you can pass Intents around.</p> <p>As far as I know instantiating a service like you do and setting a listener on it like that doesn't work. You get an error in the startService() call because the service instance isn't a class obviously; you should use <code>TimerService.class</code> instead. In your service you have an onStart(); <a href="http://developer.android.com/reference/android/app/Service.html#onStart%28android.content.Intent,%20int%29" rel="nofollow">onStart() is a deprecated function</a>, you should use onStartCommand() instead.</p> <p>Now, if you have an activity in which you want to show a clock you don't need nor want the service to update its UI directly of course, but if you'd want the service to calculate a new clock tick for you, just call startService(); As long as your service is alive, sending a new start service intent will just call the onStartCommand() with the intent you're sending along. </p> <p>If your clock is in an activity, setup a broadcast receiver inside your activity that and let your service broadcast an intent that can be received by the broadcast receiver you setup, with your new clock value passed along.</p>
 

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