Thursday, April 18, 2013

[android help] How to kill a PostDelayed Method in Android


I used postedDelayed method to refresh my Activity, which works fine. But the problem is that even when I press the Back button postdelayed method call back the previous activity..


//handler for 30000 milli-secs post delay refreshment of the activity



mHandler.postDelayed(new Runnable() {
public void run() {
dostuff();

}
}, 30000);
}

protected void dostuff() {
Intent intent = getIntent();
finish();startActivity(intent);
Toast.makeText(getApplicationContext(), "refreshed", Toast.LENGTH_LONG).show();
}

public void onBackPressed() {
super.onBackPressed();
finish();
mHandler.removeCallbacks(null);
}

protected void onStop() {
mHandler.removeCallbacks(null);
super.onStop();
}


.

stackoverflow.comm

No comments:

Post a Comment

Google Voice on T-Mobile? [General]

Google Voice on T-Mobile? So I recently switched from a GNex on Verizon to a Moto X DE on T-Mobile. I had always used Google Voice for my v...