J'ai créé une application Android sur laquelle un gestionnaire de clics sur un bouton activera toutes les 2 secondes un grille-pain apparaîtra. même de l'autre façon que j'ai un bouton d'arrêt dont je veux arrêter le fil conducteur sur cliquantcomment arrêter un gestionnaire dans android
C'est mon code
private final int FIVE_SECONDS = 2000;
public void scheduleSendLocation() {
handler.postDelayed(new Runnable() {
public void run() {
sendLocation(); // this method will contain your almost-finished HTTP calls
handler.postDelayed(this, FIVE_SECONDS);
}
}, FIVE_SECONDS);
}
protected void sendLocation() {
Toast.makeText(getApplicationContext(), "Your Location is ", Toast.LENGTH_SHORT).show();
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
btnShowLocation = (Button) findViewById(R.id.btnShowLocation);
stop = (Button) findViewById(R.id.stop);
btnShowLocation.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
scheduleSendLocation();
}
});
stop.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
// what to write here
}
});
}
monsieur quel est l'argument pour removeCallbacks() –
comment vais-je faire cela .... je ne reçois pas –
S'il vous plaît vérifier la réponse mise à jour. –