0

i made a splash screen with this youtube video turtorial here ~> http://www.youtube.com/watch?v=IHg_0HJ5iQo

i saved my files and made sure they are there now when i send it to my device the splash screen does not show up.. i dont know why.

heres my activity_main.xml code

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:background="@drawable/back_background"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

</RelativeLayout>

here is my splash.xml code

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


</LinearLayout>

heres my manafest file

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

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="17" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.example.idoser.MainActivity"
        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>
Jacob Anthony Tonna
  • 515
  • 3
  • 13
  • 27

1 Answers1

0

So after talking in chat, I see that the reason your splash screen isn't showing up is because you're not doing anything with the splash.xml layout file. If you don't inflate your splash layout or set it as a content view, then you'll never see it.

There are several ways to do this but this is the approach that I would take:

  • Create a SplashActivity
  • Make SplashActivity your launcher Activity.
  • Use a timer to start your main activity.

SplashActivity.java

package com.example.idoser;

import android.app.Activity;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;

public class SplashActivity extends Activity {

    AsyncTask<Object, Object, Object> mTimerTask;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.splash);
    }

    @Override
    protected void onResume() {
        super.onResume();

        if(mTimerTask != null) {
            mTimerTask.cancel(false);
            mTimerTask = null;
        }

        mTimerTask = new AsyncTask<Object, Object, Object>() {

            @Override
            protected Object doInBackground(Object... params) {
                try {
                    Thread.sleep(3000); /* 3 second splash screen */
                } catch(Exception e) { }

                return null;
            }

            @Override
            protected void onPostExecute(Object result) {
                super.onPostExecute(result);

                Intent intent = new Intent(SplashActivity.this, MainActivity.class);
                startActivity(intent);
                finish();
            }
        };
    }

    @Override
    protected void onPause() {
        super.onPause();

        if(mTimerTask != null) {
            mTimerTask.cancel(false);
            mTimerTask = null;
        }
    }

}

AndroidManifest.xml

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

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="17" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.idoser.SplashActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

        <activity android:name="com.example.idoser.MainActivity"
            android:label="@string/app_name" >
        </activity>
    </application>
</manifest>

Mind you this is not the best possible way to do this but it should at least get your splash screen showing and give you an idea of the direction you need to go.

Michael Celey
  • 12,645
  • 6
  • 57
  • 62