Timer inactif dans un service
Bonsoir à tous
J'ai créé un service avec un timer :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
|
public class SendMailService extends Service {
Timer timer;
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public void onCreate() {
Toast.makeText(this, "SendMailService Created", Toast.LENGTH_LONG).show();
}
@Override
public void onDestroy() {
Toast.makeText(this, "SendMailService Stopped", Toast.LENGTH_LONG).show();
}
@Override
public void onStart(Intent intent, int startid) {
Toast.makeText(this, "SendMailService Started", Toast.LENGTH_LONG).show();
timer = new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {
getMail();
}
},0,10000);
}
public void getMail() {
//do something
} |
Que je déclenche depuis mon application :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
public class SendMail extends Activity {
Button EmailButton;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
EmailButton =(Button) findViewById(R.id.StartEmail);
EmailButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
startService(new Intent(SendMail.this,SendMailService.class));
}
}
});
} |
ça compile, ça s'execute, normalement le timer devrait déclencher un getMail toutes les 10 secondes, mais il n'en n'est rien.
Je ne comprends pas.
Portant j'ai suivi les indications trés claires d'ici :
http://blog.developpez.com/android23...on-de-service/
Une idée ?
Merci