My app is loading the start page in 10 seconds. In that time of 10 sec android screen is blank. In that time I want to add the loading screen. How to add it? And tell me in app how to know the starting page is loading? And tell me how to do in my app?
-
1u can use full screen dialog or u can use splash screen.when your process starts show the dialog and when it ends dismiss it. – TheFlash Jun 28 '13 at 04:37
-
I think this link will help you: http://stackoverflow.com/questions/15452061/android-splash-screen. Good luck! – Quoc Truong Jun 28 '13 at 04:40
-
2Instead of a splashcreen, have you considered some fake data, o some tutorials, a 10 seconds splashscreen will loock your app and will be really frustrating for the user: http://cyrilmottier.com/2012/05/03/splash-screens-are-evil-dont-use-them/ – Waza_Be Jun 28 '13 at 04:42
-
What is happening in that 10 seconds? Your app design might be wrong. – Simon Jun 28 '13 at 05:25
7 Answers
use ProgressDialog.
ProgressDialog dialog=new ProgressDialog(context);
dialog.setMessage("message");
dialog.setCancelable(false);
dialog.setInverseBackgroundForced(false);
dialog.show();
hide it whenever your UI is ready with data. call :
dialog.hide();

- 1
- 1

- 6,768
- 4
- 24
- 29
-
2
-
1ProgressDialog is now deprecated. See https://stackoverflow.com/a/12842387/6205782 – vwvw Feb 24 '20 at 10:17
You can use splash screen in your first loading Activity like this:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
Thread welcomeThread = new Thread() {
@Override
public void run() {
try {
super.run();
sleep(10000); //Delay of 10 seconds
} catch (Exception e) {
} finally {
Intent i = new Intent(SplashActivity.this,
MainActivity.class);
startActivity(i);
finish();
}
}
};
welcomeThread.start();
}
Hope this code helps you.

- 373
- 5
- 14

- 28,593
- 16
- 73
- 124
-
2lets say you opening this app, and after 5s you leaving it, then after another 5s the app shows again becouse it starts main activity. Dont forget to cancel this somehow when you leave app / rotate screen etc. – RadekJ Dec 27 '16 at 10:28
-
so all the processing due to which time is taken happens in that SplashActivity ? if yes then how to create it an enclosing class , as in I created a new class called SplashActivity but now the error says it that it is not an enclosing class...please help... Sorry Im new to android – Shreyan Mehta Feb 08 '17 at 06:14
-
1This is not entirely correct. It doesn't take into account the time needed to inflate layout of splash activity, which will result in (shorter) blank screen on startup. See @yathavan answer instead. – Firzen Apr 30 '19 at 13:39
Chris Stewart wrote there:
Splash screens just waste your time, right? As an Android developer, when I see a splash screen, I know that some poor dev had to add a three-second delay to the code.
Then, I have to stare at some picture for three seconds until I can use the app. And I have to do this every time it’s launched. I know which app I opened. I know what it does. Just let me use it!
Splash Screens the Right Way
I believe that Google isn’t contradicting itself; the old advice and the new stand together. (That said, it’s still not a good idea to use a splash screen that wastes a user’s time. Please don’t do that.)
However, Android apps do take some amount of time to start up, especially on a cold start. There is a delay there that you may not be able to avoid. Instead of leaving a blank screen during this time, why not show the user something nice? This is the approach Google is advocating. Don’t waste the user’s time, but don’t show them a blank, unconfigured section of the app the first time they launch it, either.
If you look at recent updates to Google apps, you’ll see appropriate uses of the splash screen. Take a look at the YouTube app, for example.

- 4,383
- 1
- 34
- 42

- 2,051
- 2
- 18
- 25
-
8This should be accepted answer. Everything else mentioned here is garbage.. – Firzen Apr 30 '19 at 13:33
-
-
You can create a custom loading screen instead of splash screen. if you show a splash screen for 10 sec, it's not a good idea for user experience. So it's better to add a custom loading screen. For a custom loading screen you may need some different images to make that feel like a gif. after that add the images in the res
folder and make a class like this :-
public class LoadingScreen {private ImageView loading;
LoadingScreen(ImageView loading) {
this.loading = loading;
}
public void setLoadScreen(){
final Integer[] loadingImages = {R.mipmap.loading_1, R.mipmap.loading_2, R.mipmap.loading_3, R.mipmap.loading_4};
final Handler loadingHandler = new Handler();
Runnable runnable = new Runnable() {
int loadingImgIndex = 0;
public void run() {
loading.setImageResource(loadingImages[loadingImgIndex]);
loadingImgIndex++;
if (loadingImgIndex >= loadingImages.length)
loadingImgIndex = 0;
loadingHandler.postDelayed(this, 500);
}
};
loadingHandler.postDelayed(runnable, 500);
}}
In your MainActivity, you can pass a to the LoadingScreen class like this :-
private ImageView loadingImage;
Don't forget to add an ImageView in activity_main. After that call the LoadingScreen class like this;
LoadingScreen loadingscreen = new LoadingScreen(loadingImage);
loadingscreen.setLoadScreen();
I hope this will help you

- 1,353
- 2
- 18
- 35
public class Splash extends Activity {
private final int SPLASH_DISPLAY_LENGHT = 3000; //set your time here......
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
new Handler().postDelayed(new Runnable(){
@Override
public void run() {
/* Create an Intent that will start the Menu-Activity. */
Intent mainIntent = new Intent(Splash.this,MainActivity.class);
Splash.this.startActivity(mainIntent);
Splash.this.finish();
}
}, SPLASH_DISPLAY_LENGHT);
}
}

- 28,593
- 16
- 73
- 124

- 694
- 4
- 12
If the application is not doing anything in that 10 seconds, this will form a bad design only to make the user wait for 10 seconds doing nothing.
If there is something going on in that, or if you wish to implement 10 seconds delay splash screen,Here is the Code :
ProgressDialog pd;
pd = ProgressDialog.show(this,"Please Wait...", "Loading Application..", false, true);
pd.setCanceledOnTouchOutside(false);
Thread t = new Thread()
{
@Override
public void run()
{
try
{
sleep(10000) //Delay of 10 seconds
}
catch (Exception e) {}
handler.sendEmptyMessage(0);
}
} ;
t.start();
//Handles the thread result of the Backup being executed.
private Handler handler = new Handler()
{
@Override
public void handleMessage(Message msg)
{
pd.dismiss();
//Start the Next Activity here...
}
};

- 4,694
- 2
- 36
- 47

- 510
- 2
- 11
Write the code:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
Thread welcomeThread = new Thread() {
@Override
public void run() {
try {
super.run();
sleep(10000) //Delay of 10 seconds
} catch (Exception e) {
} finally {
Intent i = new Intent(SplashActivity.this,
MainActivity.class);
startActivity(i);
finish();
}
}
};
welcomeThread.start();
}