0

I already looked up similar posts on SO. I have added splash.java class, splash_layout.xml file,

i had 2 app icons appearing on desktop emulator and splash was there, but 2 icons is not good I suspect it is about manifest, what do I put in there as android.MAIN, android.DEFAULT?

This is my android manifest.xml file:

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

<uses-permission android:name="android.permission.INTERNET" />

<application
    android:allowBackup="true"
    android:icon="@drawable/logo"
    android:label="@string/app_name"
    android:theme="@style/Theme.Book">


    <something must be here for splash screen before MainActivity...>

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

This is splash java file:

package com.example.kaban.it_ebooksinfomobile;

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

public class SplashScreen extends Activity {


    private final int SPLASH_DISPLAY_LENGTH = 1000;
    private static boolean splashLoaded = false;


    @Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);

        if(!splashLoaded){
            setContentView(R.layout.splashscreen);
            splashLoaded = true ;

        /* New Handler to start the Menu-Activity
         * and close this Splash-Screen after some seconds.*/
            new Handler().postDelayed(new Runnable(){
                @Override
                public void run() {
                /* Create an Intent that will start the Menu-Activity. */
                    startActivity(new Intent(SplashScreen.this, MainActivity.class));
                    finish();
                }
            }, SPLASH_DISPLAY_LENGTH);
        }
        else {
            Intent goToMainActivity = new Intent(SplashScreen.this, MainActivity.class);
            goToMainActivity.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
            startActivity(goToMainActivity);
            finish();
        }

    }
}

But it still does not load my splash! it used to load, but with 2 app icons on virtual emulator desktop, which is stupid. I don't think it s right to make my .SplashActivity my launcher, i already did this:

<activity
            android:name=".HomeScreen"
            android:label="@string/app_name" >>     
        </activity>

        <activity
            android:name=".Splash"
            android:label="@string/title_activity_splash_screen" >>     
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />>     
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        < /activity>
ERJAN
  • 23,696
  • 23
  • 72
  • 146

5 Answers5

5

Try this:

    <activity
        android:name=".SplashScreen">
        <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="android.intent.action.MAIN" />                
        </intent-filter>
    </activity>
Paul Chernenko
  • 696
  • 5
  • 21
  • i had same thoughts, right... because my splash screen already has MainActivity to start when it finishes.. – ERJAN Mar 25 '15 at 10:31
2

Have a look at this:

<activity android:name=".MainActivity" />
    <activity
        android:name=".SplashActivity"
        android:configChanges="orientation|keyboardHidden|screenSize"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

And this is the class I use for the SplashActivity, it is similar to yours but insted of declaring the handler as anonymous I coded an internal class with WeakReference, have a look:

public class SplashActivity extends Activity {

//Private declarations
private InternalHandler mHandler;
private long mStartTime;


//Constants
private static final int GO_AHEAD = 1;
private static final long MAX_TIME = 1500L;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_splash);
    mStartTime = SystemClock.uptimeMillis();
    mHandler = new InternalHandler(this);

}

@Override
protected void onStart(){
    super.onStart();
    final Message goAHeadMessage = mHandler.obtainMessage(GO_AHEAD);
    mHandler.sendMessageAtTime(goAHeadMessage, mStartTime + MAX_TIME);

}

private void endSplash(){
    Intent main = new Intent(this, MainActivity.class);
    startActivity(main);
    finish();

}



private static class InternalHandler extends Handler {

    private WeakReference<SplashActivity> mSAWeakRef;

    public InternalHandler(SplashActivity mSARef){
        this.mSAWeakRef = new WeakReference<SplashActivity>(mSARef);
    }

    @Override
    public void handleMessage(Message msg){
        final SplashActivity mActivity = mSAWeakRef.get();
        if (mActivity == null)
            return;
        switch (msg.what){
            case GO_AHEAD:
                long elapsedTime = SystemClock.uptimeMillis() - mActivity.mStartTime;
                if (elapsedTime >= MAX_TIME) {
                    mActivity.endSplash();
                }
                break;
        }
    }
}

}

Sid
  • 14,176
  • 7
  • 40
  • 48
1

You don't need to mention intent filter.

Just declare Activity alone.

 <activity
    android:name=".MainActivity"
    android:label="@string/app_name" >
</activity>
Shadow
  • 6,864
  • 6
  • 44
  • 93
1

Please use this:

SplashView.java

import com.studentconnection.Presenter.SplashPresenter;

import android.os.Bundle;

public class SplashView extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.splash_view);
    new SplashPresenter(this);
}

}

SplashPresenter.java

import com.studentconnection.View.SigninView;
import com.studentconnection.View.SplashView;
import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Handler;
import android.os.Message;

public class SplashPresenter {
private SplashView mSplashView;
private static final int WAIT_TIME = 3000;
private static final int HANDLER_MSG = 1;
@SuppressLint("HandlerLeak")
private Handler handler = new Handler() {
    @Override
    public void handleMessage(Message msg) {
        super.handleMessage(msg);
        switch (msg.what) {
        case HANDLER_MSG:
            Intent mMainActivity = new Intent(mSplashView,
                    MainActivity.class);
            mMainActivity.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
                    | Intent.FLAG_ACTIVITY_CLEAR_TASK);
            mSplashView.startActivity(mMainActivity);
            break;

        default:
            break;
        }
    }
};

public SplashPresenter(SplashView mSplashView) {
    this.mSplashView = mSplashView;
    callHandler();
}

public void callHandler() {
    handler.sendEmptyMessageDelayed(HANDLER_MSG, WAIT_TIME);
}

}

Mainifest

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

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

<uses-permission android:name="android.permission.INTERNET" />

<application
    android:name="com.studentconnection.Support.AppStorage"
    android:allowBackup="true"
    android:icon="@drawable/app_logo"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name=".SplashView"
        android:label="@string/app_name"
        android:screenOrientation="portrait"
        android:theme="@android:style/Theme.Light.NoTitleBar" >
        <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"
        android:screenOrientation="portrait"
        android:theme="@android:style/Theme.Light.NoTitleBar" >
    </activity>
</application>

</manifest>

hope this will work..

Avishek Das
  • 661
  • 1
  • 6
  • 20
0

ok, I was lazy and did not put logs, but now I found the problem, if you do this:

<manifest>
<uses-permission android:name="android.permission.INTERNET" />

<application
    android:allowBackup="true"
    android:icon="@drawable/logo"
    android:label="@string/app_name"
    android:theme="@style/Theme.Book">

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

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

    //other activities i have here...
    <activity> ..... </activity>
    <activity> ..... </activity>

    </manifest>

It does not know where MainActivity is, it always starts with .SplashScreen, but no MainAcitivty mentioned, so put this ( i m not sure order matters) right after splash activity tag and your manifest looks like this:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"    

<uses-permission android:name="android.permission.INTERNET" />

<application
    android:allowBackup="true"
    android:icon="@drawable/logo"
    android:label="@string/app_name"
    android:theme="@style/Theme.Book">

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

and so it knows about Mainactivity it must go to after splash screen is gone.

ERJAN
  • 23,696
  • 23
  • 72
  • 146