-2

i'm developing an android app but can't seem to get the splash screen to start before the main activity yet on all my other app's this has been no problem

What could be the problem here? There's no problem in the code.

package com.example.soundboardapp;



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

public class splash 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);

        this.requestWindowFeature(Window.FEATURE_NO_TITLE);

        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(splash.this, MainActivity.class);
                    finish();
                    startActivity(intent);
                }
            }
        };
        mythread.start();
    }
}

Theres a splash activity to correspond to the code.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/intro22"
     >

    <LinearLayout
        android:id="@+id/linearLayout1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:gravity="center" >



    </LinearLayout>

    <ProgressBar
        android:id="@+id/progressBar1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="184dp" />

</RelativeLayout>

What could be the problem?

roukzz
  • 129
  • 1
  • 2
  • 10

2 Answers2

0

You shouldn't use a thread, instead of the entire thread, use this:

new Handler().postDelayed(new Runnable() {
 public void run() {
                    Intent intent = new Intent(splash.this, MainActivity.class);
                    finish();
                    startActivity(intent);

}, splashTime);
Sean
  • 5,176
  • 2
  • 34
  • 50
0

I guess you don't have the splash activity set as the starting activity of your application. Check the AndroidManifest.xml file if you have something like this there:

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

Let me know if that was the problem.

zbr
  • 6,860
  • 4
  • 31
  • 43