Android Splash Screen With Progress Bar Example
In this post, we are going to create a simple Android Splash Screen with a progress bar.
1. splash_screen.xml, the layout file for the splash screen.
2. SplashScreen.java, the splash screen activity. The doWork method is a dummy method for doing some dummy sleeps, replace the content of this method with some of your important tasks that need to be done before the app starts.
public class SplashScreen extends Activity { private ProgressBar mProgress; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Show the splash screen setContentView(R.layout.splash_screen); mProgress = (ProgressBar) findViewById(R.id.splash_screen_progress_bar); // Start lengthy operation in a background thread new Thread(new Runnable() { public void run() { doWork(); startApp(); finish(); } }).start(); } private void doWork() { for (int progress=0; progress<100; progress+=10) { try { Thread.sleep(1000); mProgress.setProgress(progress); } catch (Exception e) { e.printStackTrace(); Timber.e(e.getMessage()); } } } private void startApp() { Intent intent = new Intent(SplashScreen.this, MainActivity.class); startActivity(intent); } }
3. Make the SplashScreen the launcher class, in the manifest file AndroidManifest.xml
Search within Codexpedia
Custom Search
Search the entire web
Custom Search
Related Posts