Procedure
  1. Start Eclipse IDE.
  2. Create a new project.
  3. Create two Java files, one is MainActivity.java file and the other is A.java.
  4. Create two XML files, one is activity_main.xml file and the other is home.xml for layout design.
  5. Declare a variable of the TimerTask.
  6. Then declare a TimerTask function like this:
  1. TimerTask ttt=new TimerTask() {
  2. public void run() {
  3. Intent i=new Intent(getApplicationContext(),A.class);
  4. startActivity(i);
  5. }
  6. };
  7. Timer t=new Timer();
  8. t.schedule(ttt, 4000);
  9. }
The following is the code.
  1. MainActivity.java
  2. package com.example.splashscreenn;
  3. import java.util.Timer;
  4. import java.util.TimerTask;
  5. import android.os.Bundle;
  6. import android.app.Activity;
  7. import android.content.Intent;
  8. import android.view.Menu;
  9. public class MainActivity extends Activity {
  10. TimerTask ttt;
  11. @Override
  12. protected void onCreate(Bundle savedInstanceState) {
  13. super.onCreate(savedInstanceState);
  14. setContentView(R.layout.activity_main);
  15. ttt = new TimerTask() {
  16. @Override
  17. public void run() {
  18. Intent i = new Intent(getApplicationContext(), A.class);
  19. startActivity(i);
  20. }
  21. };
  22. Timer t = new Timer();
  23. t.schedule(ttt, 4000);
  24. }
  25. }
A.java
  1. package com.example.splashscreenn;
  2. import android.app.Activity;
  3. import android.os.Bundle;
  4. public class A extends Activity {
  5. @Override
  6. protected void onCreate(Bundle savedInstanceState) {
  7. super.onCreate(savedInstanceState);
  8. setContentView(R.layout.home);
  9. }
  10. }
activity_main.xml
  1. <RelativeLayout
  2. xmlns:android="http://schemas.android.com/apk/res/android"
  3. xmlns:tools="http://schemas.android.com/tools"
  4. android:layout_width="match_parent"
  5. android:layout_height="match_parent"
  6. android:background="#ff0000"
  7. android:paddingBottom="@dimen/activity_vertical_margin"
  8. android:paddingLeft="@dimen/activity_horizontal_margin"
  9. android:paddingRight="@dimen/activity_horizontal_margin"
  10. android:paddingTop="@dimen/activity_vertical_margin"
  11. tools:context=".MainActivity" >
  12. <TextView
  13. android:layout_width="wrap_content"
  14. android:layout_height="wrap_content"
  15. android:text="Abhijeet" />
  16. </RelativeLayout>
home.xml
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout
  3. xmlns:android="http://schemas.android.com/apk/res/android"
  4. android:layout_width="match_parent"
  5. android:layout_height="match_parent"
  6. android:orientation="vertical" >
  7. <Spinner
  8. android:id="@+id/spinner1"
  9. android:layout_width="match_parent"
  10. android:layout_height="wrap_content" />
  11. <Spinner
  12. android:id="@+id/spinner2"
  13. android:layout_width="match_parent"
  14. android:layout_height="wrap_content" />
  15. <Spinner
  16. android:id="@+id/spinner3"
  17. android:layout_width="match_parent"
  18. android:layout_height="wrap_content" />
  19. </LinearLayout>
Output