Tinniam V. Ganesh
Tinniam V. Ganesh

Reputation: 2079

Application not loading after Splash screen

I am having an issue where the application does not load after including the Splash screen to the application. This is the code for the SplashScreen.java & the Manifest file. I am not sure what I am missing. I have gone over this several times and am unable to spot the error. I have gone thro' similar posts but could find the answer. Please help

    public class SplashScreen extends Activity {
private long ms=0;
    private long splashTime=2000;
private boolean splashActive = true;
private boolean paused=false;
@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.splash);
     Thread mythread = new Thread() {
    public void run() {
        try {
            while (splashActive && ms < splashTime) {
                if(!paused)
                    ms=ms+100;
                sleep(100);
            }
        } catch(Exception e) {}
        finally {
            Intent intent = new Intent(SplashScreen.this, TotalControl.class);
            startActivity(intent);
        }
        }
};
mythread.start(); 
}

The Manifest file is as follows

    <application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.tvganesh.totalcontrol.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="com.tvganesh.totalcontrol.TotalControl"
        android:label="@string/app_name" >
    </activity>
</application>

After the Splash Screen which it display it is supposed to switch to TotalControl.class. But the I get the message "The Application stopped unexpectedly"

Can you let me know what I am missing?

Upvotes: 0

Views: 645

Answers (3)

Tinniam V. Ganesh
Tinniam V. Ganesh

Reputation: 2079

I have solved the problem. This appears to be a known bug in AndEngine and the fix is add the following line to the Manifest file

android:configChanges="orientation|screenSize"

Thanks for all your help.

Upvotes: 0

Naresh Sharma
Naresh Sharma

Reputation: 4323

I think this will work for you Don't use threads to show the splash.

public class SplashScreen extends Activity {

        protected int _splashTime = 5000; 

        private Thread splashTread;
        MyCount counter = new MyCount(4000, 4000);
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.splash);

            counter.start();
        }
         public class MyCount extends CountDownTimer
         {
             public MyCount(long csecond, long countDownInterval) 
             {
                  super(csecond, countDownInterval);
             }

            @Override
            public void onFinish() {
                finish();
                Intent intent = new Intent();
                intent.setClass(SplashScreen.this, TotalControl.class);
                startActivity(intent);

            }

            @Override
            public void onTick(long arg0) {

            }
       }
    }

Upvotes: 1

npace
npace

Reputation: 4258

Don't use Thread.sleep - you have no guarantee that it will start up again exactly after 100ms. Use a Handler instead:

getWindow().getDecorView().getHandler().postDelayed(new Runnable()
    {

        @Override
        public void run()
        {
            Intent intent = new Intent(SplashScreen.this, TotalControl.class);
            startActivity(intent);
        }
    }, splashTime);

Upvotes: 1

Related Questions