You can, for example, use the Handler and call its .removeCallbacks () and .postDelayed () methods every time the user interacts with the dialog.
When interacting, the .removeCallbacks () method cancels the execution of .postDelayed (), and immediately after that starts a new Runnable with .postDelayed ()
Inside this Runnable, you can close the dialog.
// a dialog final Dialog dialog = new Dialog(getApplicationContext()); // the code inside run() will be executed if .postDelayed() reaches its delay time final Runnable runnable = new Runnable() { @Override public void run() { dialog.dismiss(); // hide dialog } }; Button interaction = (Button) findViewById(R.id.bottom); final Handler h = new Handler(); // pressing the button is an "interaction" for example interaction.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { h.removeCallbacks(runnable); // cancel the running action (the hiding process) h.postDelayed(runnable, 5000); // start a new hiding process that will trigger after 5 seconds } });
To track user interactions, you can use:
@Override public void onUserInteraction(){ h.removeCallbacks(runnable);
What is available in your business.
source share