1

I was trying to get a small image to show up before my Main Activity starts. This is my current coding in the android manifest

<application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >

        <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>
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="com.example.test.MAINACTIVITY" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
    </application>

whatever I do, my splash screen does not start. They start separately, but never together, (I still haven't put a timer in my splash image as I want to check whether it works or not and it isn't working)

  • may be your splash screen starts then immediately navigates to MainActivity so you don't see the change. put a delay and then give it a try – Raghunandan Sep 30 '13 at 14:57
  • What is the code in the Splash activity? – nhgrif Sep 30 '13 at 14:58
  • `package com.example.test; import android.app.Activity; import android.os.Bundle; public class Splash extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.splash); } }` This is the current code for splash, do you require the XML code as well?. I've checked a tutorial which shows the exact same thing, but in his case, the application stops at the splash screen! – user2831076 Sep 30 '13 at 15:02
  • @user2831076 you can start new activity from Splash class. **startActivity(new Intent(Splash.this, MainActivity.class));** **finish();** – Kanwaljit Singh Sep 30 '13 at 15:14
  • @user2831076 i updated your splash class. now this works fine. i am sure. try this. – Kanwaljit Singh Oct 01 '13 at 08:36

4 Answers4

1

Remove

<intent-filter>
    <action android:name="com.example.test.MAINACTIVITY" />
    <category android:name="android.intent.category.DEFAULT" />
</intent-filter>

Use below code in splash screen after desired time

Intent intent=new Intent(this,MAINACTIVITY.class);
startActivity(intent);
finish();  //To close splashscreen when MAINACTIVITY loads

The above code starts with splash screen and after some time start your main activity

Piyush
  • 2,040
  • 16
  • 14
  • the first block is to remove from the Manifest file you provided in your post, the second block is to add to the java file defining your Splash activity , you should add it in the onCreate, after waiting for a timer to finish – Tourki Sep 30 '13 at 15:09
  • this didn't do it either! I'm not sure what to do now! I've tried following exactly what the tutorial showed, and yet mine does not work! – user2831076 Sep 30 '13 at 15:35
  • I copied the entire code as is and it still doesn't work! Should I try doing the entire thing from scratch again? – user2831076 Sep 30 '13 at 15:51
1

You should remove the <intent-filter> section from your MainActivity declaration ,
and launch the MainActivity from the splashActivity using a simple intent and startActivity call.

Tourki
  • 1,785
  • 15
  • 22
1

Try this.

        <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>
        <activity
            android:name=".MainActivity" >
        </activity>
    </application>

Code for your Splash Class-

package com.example.test;
import android.app.Activity; 
import android.os.Bundle; 
public class Splash extends Activity 
{ 
@Override 
protected void onCreate(Bundle savedInstanceState) 
{ // TODO Auto-generated method stub 
super.onCreate(savedInstanceState); 
setContentView(R.layout.splash); 

final Handler handle = new Handler();
Runnable delay = new Runnable() {
public void run() {
startActivity(new Intent(Splash.this, MainActivity.class));
                finish();
            }
        };
        handle.postDelayed(delay,5000);
} 
}

its delay next intent 5 second. you can set time according to you.

Kanwaljit Singh
  • 4,339
  • 2
  • 18
  • 21
0

Use This:

<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>
    <activity
        android:name=".MainActivity" >
    </activity>
</application>

and This :

public class Splash extends Activity {

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

    final Handler handler = new Handler();
    handler.postDelayed(new Runnable() {
        public void run() {
            Intent mInHome = new Intent(Splash.this, MainActivity.class);
            Splash.this.startActivity(mInHome);
            Splash.this.finish();
        }
    }, 3000);
}
}
Vikrant_Dev
  • 430
  • 2
  • 15