Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You can create a timer and then hide the dialog like this:</p> <pre><code>Timer tShow = new Timer(); Timer tHide = new Timer(); // This timer will show the popup every 10 second tShow.schedule(new TimerTask(){ public void run(){ helpDialog.show(); Date d = new Date(); d.setSeconds(d.getSeconds()+20); //This will hide the popup after 20 secnds tHide.schedule(new TimerTask(){ public void run(){ helpDialog.dismiss(); } },d); } },0,10*1000); </code></pre> <p>Declare Timers and Dialog as variables of class. But, i dont understand that if you show popup every 10sec and hide every 20sec how is it going to work?</p> <p><strong>EDIT</strong></p> <pre><code>private Timer tShow = new Timer(); private Timer tHide = new Timer(); private AlertDialog helpDialog; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); AlertDialog.Builder helpBuilder = new AlertDialog.Builder(MainActivity.this); helpBuilder.setTitle("Pop Up"); helpBuilder.setMessage("This is a Simple Pop Up"); helpBuilder.setPositiveButton("OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { // Do nothing but close the dialog } }); helpBuilder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // Do nothing } }); helpBuilder.setNeutralButton("Neutral", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // Do nothing } }); helpDialog = helpBuilder.create(); // This timer will show the popup every 10 second tShow.schedule(new TimerTask(){ @Override public void run(){ abc(); } },0,10*1000); } public void abc(){ this.runOnUiThread(my_Function); } private Runnable my_Function = new Runnable() { @Override public void run() { helpDialog.show(); Date d = new Date(); d.setSeconds(d.getSeconds()+20); //This will hide the popup after 20 secnds tHide.schedule(new TimerTask(){ public void run(){ helpDialog.dismiss(); } },d); } }; @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload