I created a new HelloService class. I added this to the Android manifest. Xml
public class HelloService extends Service { private Timer timer = new Timer(); private long INTERVAL = 5000; public void onCreate() { super.onCreate(); startservice(); } private void startservice() { timer.scheduleAtFixedRate( new TimerTask() { public void run() { Log.d("servy", "This proves that my service works."); } }, 0, INTERVAL); ; } private void stopservice() { if (timer != null){ timer.cancel(); } } @Override public IBinder onBind(Intent arg0) { return null; } }
My other activity calls it this way:
Intent helloservice = new Intent(this, HelloService.class); startService(helloservice);
For some reason, I set a breakpoint in my new HelloService ... but it didn't even hit. He also does not register.
Edit: "Unable to start Intent service {cmp = com.examples.hello / .HelloService}: not found"
What does this mean? ... I created HelloService.java in the same place as everything else ...
solved. I fixed the manifest file. Thanks Nikola Smiljanic
<service android:name=".HelloService"/>
at
<service android:name="HelloService"></service>
java android timer service
TIMEX Feb 15 2018-10-15T00 : 00Z
source share