How to change ToggleButton state programmatically?

Got it. Kind of.

I had this

    protected void onResume() {
        super.onResume();

        Intent intent;

        if ((intent = getIntent()) != null && MainActivity.STOP.equals(intent.getAction())) {
            disable();

            toggle.setChecked(false);

            finish();
        }
    }

But the call to finish wasn't actually doing anything. I removed it and now it works. Not a clue why this fixed it.

Someone care to explain?


It should work.

Check that you don't have a call to setChecked(true) somewhere else in the code that is executed after you set it to false. Perhaps inside an OnCheckedChangeListener?