Search code examples
androidandroid-activity

close an activity after some time


I'm trying to make a dice rolling app and I want to run an activity which displays an image of the result when a button is pressed and close it after a few seconds. So how can I do this?

Maybe there's another way to display an image on top of my activity without calling a new activity? I'm not sure.

I've read some things about timers but I don't really get it. And I know people will tell me to let the user tap to dismiss the window but for this app I'm sure I want it gone automatically.


Solution

  • you can use this:

     Timer t = new Timer();
     t.schedule(new TimerTask() {
            @Override
            public void run() {             
                image.setVisibility(View.GONE);
                // If you want to call Activity then call from here for 5 seconds it automatically call and your image disappear....
            }
     }, 5000);