Skip to content Skip to sidebar Skip to footer

Handler.removecallbacks Not Working

public class MainActivity extends AppCompatActivity { int total = 0,k=0,j=0,i; public EditText editText; private int mInterval = 1000; Handler mHandler = new Handl

Solution 1:

OnDestroy() to destroy the handler, this is where I don't know what to do

Sanjay change your OnDestroy() function to

@OverridepublicvoidonDestroy() {
    mHandler.removeCallbacksAndMessages(null);
    super.onDestroy();  // notice: we call super after removing handler callbacks and messages
}

Solution 2:

try to make handler and runnable as a static

publicstaticHandlerhandler=newHandler();
 publicstatic Runnable runnable;

works for me

Post a Comment for "Handler.removecallbacks Not Working"