Thursday, April 3, 2014

Android implement Splash Screen Using Timer

In order to implement splash screen we are going to create a separate activity for splash and once it closes we launch our main activity.


For more update about android click here

XML file for your splash screen.

<?xml version=”1.0″ encoding=”utf-8″?>
<RelativeLayout xmlns:android=”http://schemas.android.com/apk/res/android”
android:layout_width=”match_parent”
android:layout_height=”match_parent”
android:background=”@drawable/image” >
<ImageView
android:id=”@+id/imgLogo”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:layout_centerInParent=”true”
android:src=”@drawable/your_logo” />
<TextView
android:layout_width=”fill_parent”
android:layout_height=”wrap_content”
android:layout_marginBottom=”10dp”
android:textSize=”12dp”
android:textColor=”YOUR COLOR”
android:gravity=”center_horizontal”
android:layout_alignParentBottom=”true”
android:text=”www.varemads.com” />
</RelativeLayout>

Add the following code in SplashScreen.java activity. In this following code a handler is used to wait for specific time and once the timer is out we launched main activity.

public class SplashScreen extends Activity {
// Splash screen timer
private static int SPLASH_TIME_OUT = 3000;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
// This method will be executed once the timer is over
// Start your app main activity
Intent i = new Intent(SplashScreen.this, MainActivity.class);
startActivity(i);
finish();
}
}, SPLASH_TIME_OUT);
}
}

Run the application, you will see the splash screen for 3 sec and then your main activity will be launched.

Click here for more update about android

No comments:

Post a Comment