i trouvé ce code pour minuteries Android, public class MyActivity étend l'activité {Android Timers Problème
private Timer myTimer;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
myTimer = new Timer();
myTimer.schedule(new TimerTask() {
@Override
public void run() {
TimerMethod();
}
}, 0, 1000);
}
private void TimerMethod()
{
//This method is called directly by the timer
//and runs in the same thread as the timer.
//We call the method that will work with the UI
//through the runOnUiThread method.
this.runOnUiThread(Timer_Tick);
}
private Runnable Timer_Tick = new Runnable() {
public void run() {
//This method runs in the same thread as the UI.
//Do something to the UI thread here
}
};
} Je dois comprendre une chose ... les commentaires disent que cette méthode fonctionne dans le même fil Comme l'Ui, cela signifie que cette méthode continuera à fonctionner même si l'écran est éteint ou si l'activité est poussée vers l'arrière-plan, par exemple. en cas d'appel téléphonique entrant?