Yusef Bee
Yusef Bee

Reputation: 281

Splash in Android not working

I'm trying to create a splash screen for my app in android but it will not show up at all. The code i'm using is 4 different files. Here it is:

Splash.java

     package com.timchecklist;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;

public class Splash extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        Thread Timer = new Thread() {
            public void run() {

                try {
                    sleep(3000);
                    startActivity(new Intent("com.timchecklist.SPLASHNEW"));

                } catch (InterruptedException e) {
                    e.printStackTrace();
                } finally {
                    finish();
                }
            }
        };
        Timer.start();
    }

}

SplashNew.java

   package com.timchecklist;

import android.app.Activity;
import android.os.Bundle;
import android.view.Window;

public class SplashNew extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.splash);

    }

}

Splash.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:background="@drawable/pic1"
    android:gravity="center"
    android:orientation="vertical" >

</LinearLayout>

AndroidManifest.xml

  <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.timchecklist"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="7" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:name=".TimCheckListActivity"
            android:label="@string/app_name"
            android:theme="@android:style/Theme.NoTitleBar" >
        </activity>
        <activity
            android:name=".SplashNew"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

Please tell me what I'm doing wrong here. Any help would be appreciated. Thanks guys:)

Upvotes: 1

Views: 306

Answers (4)

Yvan RAJAONARIVONY
Yvan RAJAONARIVONY

Reputation: 571

There is better way to make a splash screen. Declare an handler like this, which call the next activity to launch after a precised time:

private Handler splashHandler = new Handler() {

@Override
    public void handleMessage(Message msg) {
        switch (msg.what) {

            Intent intent = new Intent(Splash.this, OtherActivity.class);
            startActivity(intent);
            finish();

            break;
        }
        super.handleMessage(msg);
    }
};

Then execute the code after some delay like this in onCreate:

Message msg = new Message();
splashHandler.sendMessageDelayed(msg, SPLASHTIME);

Upvotes: 0

Dheeresh Singh
Dheeresh Singh

Reputation: 15701

There is no entry of SplashNew in menifest file ......

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.timchecklist"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk android:minSdkVersion="7" />

<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name" >
    <activity
        android:name=".TimCheckListActivity"
        android:label="@string/app_name" >

    </activity>

     <activity
        android:name=".Splash"
        android:label="@string/app_name" >
        <intent-filter>
           <action android:name="android.intent.action.MAIN" />
           <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

</application>

</manifest>

enter image description here

Upvotes: 0

Nirali
Nirali

Reputation: 13825

You should add SplashNew in Manifest file.

Try below code

 setContentView(R.layout.splash);

 new Thread(new Runnable() {

        public void run() {
                // TODO Auto-generated method stub      
                try {

                    Thread.sleep(2000);
                    startActivity(new Intent(getApplicationContext(),EquipmentCategory.class));
                    finish();

                } catch (InterruptedException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }

            }
        }).start();

Upvotes: 0

Samir Mangroliya
Samir Mangroliya

Reputation: 40416

i think Splash should be launcher activity first . and where you declare SPLASHNEW in AndroidManifest File ?.

Upvotes: 1

Related Questions