Advertisemnet

Earn Extra Money At Home. Starting from Now!!!

Thursday, March 29, 2012

Android Chapter 7 : Loading Screen

Hello everyone, welcome to Android Chapter 7 : Loading Screen.
It's mihiran again. In this chapter we are going to look, how to create a simple loading screen in android.

So lets get started.

Loading screen is a very useful feature to give a professional look to your app. In my application I'm using it in several places.. First look at it and how nice it is..

                       Starting                                          Login                                           Log off



In my case I'm using a Thread to handle this. Coding part is very simple. When your are using thread, you must have to surround it by try catch block. Lets see how I have used it in my Starting page.

package com.solution.dude;
public class SolutionDudeActivity extends Activity {
/** Called when
the activity is first created.
**/
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final ProgressDialog pd.new ProgressDialog(this);
pd.setProgressStyle(ProgressDialog.STYLE_SPINNER);
pd.setMessage("Loading ...");
pd.show();
setContentView(R.layout.main);
new Thread(new Runnable() {
public void run() {
try
{
Thread.sLeep(2000);
pd.dismiss();
}
catch
(InterruptedException e) {
e.printStackTrace();
}).start();

You have to have a runnable thread here. Otherwise it won't work properly. I want to pop up the loading screen for two seconds. That is why I'm using 2000 here.
You can have a object from ProgressDialog class and set the style, message and many more. In here I'm using progressDialog.STYLE_SPINNER. If you use progressDialog.STYLE_HORIZONTAL you'll see it like below.


And that's it.
See you in the next chapter again !
Android

6 comments: