Android Disable Activity From User Touch

Apr 13, 2019
public class MainActivity extends AppCompatActivity {    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);        // disable activity        enableActivity(false)    }    private void enableActivity(Boolean isEnabled) {        if (!isEnabled) {            getWindow().setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE,                WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE);        }        else {            getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE);        }    }}

NOTE: Alternatively, you can show an overlay transparent dialog to achieve the same result with some UI hint (black opaque overlay with icon/progressbar).

❤️ Is this article helpful?

Buy me a coffee ☕ or support my work via PayPal to keep this space 🖖 and ad-free.

Do send some 💖 to @d_luaz or share this article.

✨ By Desmond Lua

A dream boy who enjoys making apps, travelling and making youtube videos. Follow me on @d_luaz

👶 Apps I built

Travelopy - discover travel places in Malaysia, Singapore, Taiwan, Japan.