Hi! I'm having trouble coding a service example. My service is a very simple one that only displays a message at a given interval. Here's my code:
AndroidManifest.xml
<service android:name=".BuggingService" android:enabled="true" />
BuggingService.java
public class BuggingService extends Service {
private Timer timer;
private int counter;
private TimerTask executeAgain = new TimerTask() {
@Override
public void run() {
Toast.makeText(getApplicationContext(), "I poop on you", Toast.LENGTH_LONG).show();
}
};
@Override
public void onCreate() {
timer = new Timer("buggingService");
timer.scheduleAtFixedRate(executeAgain, 0, 5000);
}
@Override
public IBinder onBind(Intent arg0) {
// TODO Auto-generated method stub
return null;
}
}
Hello.class
startService(new Intent(this, BuggingService.class));
The service is running, but the message is never displayed and I don't understand why. If I debug my service the timer is executing every 5 seconds. Can anyone offer an explanation for this?
Thanks in advance.
AndroidManifest.xml
<service android:name=".BuggingService" android:enabled="true" />
BuggingService.java
public class BuggingService extends Service {
private Timer timer;
private int counter;
private TimerTask executeAgain = new TimerTask() {
@Override
public void run() {
Toast.makeText(getApplicationContext(), "I poop on you", Toast.LENGTH_LONG).show();
}
};
@Override
public void onCreate() {
timer = new Timer("buggingService");
timer.scheduleAtFixedRate(executeAgain, 0, 5000);
}
@Override
public IBinder onBind(Intent arg0) {
// TODO Auto-generated method stub
return null;
}
}
Hello.class
startService(new Intent(this, BuggingService.class));
The service is running, but the message is never displayed and I don't understand why. If I debug my service the timer is executing every 5 seconds. Can anyone offer an explanation for this?
Thanks in advance.