Creating a thread for SpashScreen

If you want the SplashScreen to appear for a few seconds and then automatically continue onto the menu without the user have any interaction, you should use a thread. 

1. The first thing you need to do is declare and instantiate a thread.

Do so by: Thread thread = new Thread()

Image

2. Create a method called try. It should be public and void as it is a process method. 

Image

3. The next part is the try which will have the timer inside. Write the word try which is a reserved word in Java, you should then open the brackets. Within the try the write “sleep(3000);” This is written in milliseconds and can be changed to whatever you want. I have chosen to have mine run for 3 seconds (or 3000 milliseconds)

Image

4. Now its the catch. This will catch any exceptions. You should write catch. This is also a reserved word in Java. Within its parameters you should include then InterruptedExpection e. Now open the brackets and place within them e.printStackTrace():

It should look something like this:

Image

5. Now its time to write the finally which is yet another reserved word in Java. After writing finally open the brackets. Within here we are going to write an Intent which will enable us to continue onto the next page. Being by declaring an new intent and instantiate it.

Do so by: Intent loadmenu = new Intent();

Within the parameters we are now going to include the relevant Java files which we want it to load. This should be the current page first which should be the Splashscreen.this. The next one is the page you want it to continue onto. This can be anything you like I have chosen mine to continue onto the mainMenu.class

It should look like this: Image

 

6. Now close the run method and the thread. 

7. The last part you need to do is start the thread. You can do so by saying “thread.start();”.

It should look like this: 

Image

 

The complete version should look something like this:

Image

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s