user1165694
user1165694

Reputation: 1285

Activity after splash screen

Once my splash screen display for 1000ms I receive an error stating "The application has stopped unexpectedly. Please try again." It seems an activity that is supposed to start after the splash screen is not working. before the splash screen, everything worked fine. Logcat shows the following error " E/AndroidRuntime(5480): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.xxxxx.home/com.xxxxx.home.xxxxx}: java.lang.NullPointerException. I beleive the issue is with my Splash Class but cannot pin point where. Any insight would be greatly appreciated.

public class Splash extends Activity{

private final int SPLASH_DISPLAY_LENGTH = 1000;

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


    new Handler().postDelayed(new Runnable(){
        @Override
        public void run() {

            Intent openxxxxx = new Intent("com.xxxxx.home.XXXXX");
            startActivity(openxxxxx);

        }
    }, SPLASH_DISPLAY_LENGTH);
}

}

Upvotes: 1

Views: 2282

Answers (1)

Aerrow
Aerrow

Reputation: 12134

Here is the complete code you can use this,

package com.fsp.slideview;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.Window;

public class ImageSplashActivity extends Activity {
    /**
     * The thread to process splash screen events
     */
    private Thread mSplashThread;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.splash);

        final ImageSplashActivity sPlashScreen = this;

        mSplashThread = new Thread() {
            @Override
            public void run() {
                try {
                    synchronized (this) {
                        wait(2000);
                    }
                } catch (InterruptedException ex) {
                }

                finish();
                Intent intent = new Intent();
                intent.setClass(sPlashScreen, SlideMainActivity.class);
                startActivity(intent);
            }
        };

        mSplashThread.start();
    }

    @Override
    public boolean onTouchEvent(MotionEvent evt) {
        if (evt.getAction() == MotionEvent.ACTION_DOWN) {
            synchronized (mSplashThread) {
                mSplashThread.notifyAll();
            }
        }
        return true;
    }
}

Upvotes: 3

Related Questions