For example, if we consider the snippet code below:
public class HandlerExample extends AppCompatActivity {
private Handler mLeakyHandler = new Handler();
private TextView myTextBox;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_samples);
myTextBox = (TextView) findViewById(R.id.tv_handler);
// Post a message and delay its execution for 10 seconds.
mLeakyHandler.postDelayed(new Runnable() {
@Override
public void run() {
myTextBox.setText("Done");
}
}, 1000 * 10);
}
}
When the Activity
gets destroyed, whether by a configuration change or another reason, the Runnable
will not. The same goes for Asynctask
s.
My question is, what makes it not being destroyed even if it's declared in that Activity
?
Consider that I am asking about the why.