0

This code is homepage of my app. For this app i want to create splash .

main app code:-

 package com.Wase.edittext;

import java.util.Timer;
import java.util.TimerTask;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.text.format.Time;
import android.widget.EditText;

public class Splash extends Activity {

Timer timer = new Timer();

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.splash_logo);
    Time.schedule(new TimerTask() {
           public void run() {
               Intent intent = new Intent(Splash.this, MyAndroidAppActivity.class);
               startActivity(intent);
               finish();
           }
        }, 5000);
     }
}

This my code for splash.. please see the mistake amd tell me ..

Shashank
  • 21
  • 7

3 Answers3

0

First of all create one new XML file and use whatever design you want and after that create activity (java) file and use below code and change your screen and variable name as per your requirement.

public class Splash extends Activity {

Timer timer = new Timer();

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.splash);
    timer.schedule(new TimerTask() {
           public void run() {
               Intent intent = new Intent(Splash.this, MyAndroidAppActivity.class);
               startActivity(intent);
               finish();
           }
        }, 5000);
     }
  }

and this is your splash.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/splash"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFF"
tools:context=".IMyCompany" >

<ImageView
    android:id="@+id/imageView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="153dp"
    android:src="@drawable/logo" />

</RelativeLayout>

it will move to new activity after 5 seconds.

InnocentKiller
  • 5,234
  • 7
  • 36
  • 84
0
public class SplashScreen extends Activity {
    public SplashScreen instance;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.xml_splashscreen);
        if (instance != null) {
            instance.finish();
        }
        instance = this;


        Thread threadMenu = new Thread(new Runnable() {
            public void run() {
                try {
                    // sleep 3 second and go next page
                    Thread.sleep(400);
                    // Check Vefication Success then Load HomeScreen Check

                        Intent splash = new Intent(getBaseContext(),
                                MyAndroidAppActivity .class);
                        startActivity(splash);
                        finish();
                        overridePendingTransition(R.anim.push_in_from_left,
                                R.anim.push_out_to_right);



                    }

                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });
        threadMenu.start();
    }
}

in manifest file :

<activity
            android:name="com.demo.SplashScreen"
            android:label="@string/app_name"
            android:screenOrientation="sensorPortait" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".com.demo.MyAndroidAppActivity"
            android:configChanges="keyboardHidden"
            android:screenOrientation="sensorPortait"
            android:windowSoftInputMode="stateHidden" />
dipali
  • 10,966
  • 5
  • 25
  • 51
0
use this code
====
public class SplashScreenActivity extends Activity {
    final int splashTimeOut = 3000;
    ImageView imgSplash;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.splashscreen);
        imgSplash = (ImageView) findViewById(R.id.imgsplash);
        setContentBasedOnLayout();

        // TODO Auto-generated method stub
        Thread splashThread = new Thread() {
            int wait = 0;

            @Override
            public void run() {
                try {
                    super.run();
                    while (wait < splashTimeOut) {
                        sleep(100);
                        wait += 100;
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                } finally {

                    //If You Want To Do Something Write Here Your Code

                }
            }  
        };
        splashThread.start();
    }

    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }
}
ishu
  • 1,322
  • 1
  • 11
  • 15