0

EDIT: Fixed my main problem. Now I am having problems opening one activity and moving to the next. From my understanding, the manifest tells ".Main" to open which opens the splash.xml file. The sleep command rests on this for 5 seconds than it moves on to the ".menu" and this opens main.xml. However, when I run this app in the emulator only main.xml shows and skips the 5 second intro.

Here are my pages of code:

>**Main.java**

>package com.pooks.thebasics;

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

>public class Main extends Activity {
>
    @Override
    protected void onCreate(Bundle TravisIsAwesome) {
        super.onCreate(TravisIsAwesome);
        setContentView(R.layout.splash);
        Thread logoTimer = new Thread(){
            public void run(){
                try{
                    sleep(5000);
                    Intent menuIntent = new Intent("com.pooks.thebasics.MENU");
                    startActivity(menuIntent);
                } catch (InterruptedException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
>               
                finally{
                    finish();
                }
            }
        };
        logoTimer.start();
    } 
}

   **splash.xml**   

    <?xml version="1.0" encoding="utf-8"?>
        <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@drawable/splash_back"
            android:orientation="vertical" >

        </LinearLayout>



>**menu.java**
>
    package com.pooks.thebasics;   
    import android.app.Activity;
    import android.os.Bundle;
> 
    public class menu extends Activity {

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            // TODO Auto-generated method stub
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
        }

        @Override
        protected void onPause() {
            // TODO Auto-generated method stub
            super.onPause();
        }   
    }



>**main.xml**
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="center"
        android:background="@drawable/background1"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/textView1"
            android:layout_width="fill_parent"
            android:layout_height="54dp"
            android:gravity="center"
            android:height="25dp"
            android:lines="1"
            android:paddingBottom="@dimen/activity_horizontal_margin"
            android:paddingRight="@dimen/activity_vertical_margin"
            android:paddingTop="@dimen/activity_vertical_margin"
            android:text="@string/hello_world"
            android:textAppearance="?android:attr/textAppearanceSmallInverse"
            android:textStyle="bold"
            android:typeface="serif" />

        <TextView
            android:id="@+id/textView2"
            android:layout_width="fill_parent"
            android:layout_height="54dp"
            android:height="25dp"
            android:lines="1"
            android:paddingBottom="@dimen/activity_horizontal_margin"
            android:paddingRight="@dimen/activity_vertical_margin"
            android:paddingTop="@dimen/activity_vertical_margin"
            android:text="I&apos;m pookie jeans"
            android:textAppearance="?android:attr/textAppearanceSmallInverse"
            android:textStyle="bold"
            android:typeface="serif"
            android:gravity="center" />

        <Button
            android:layout_width="224dp"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:gravity="center"
            android:text="Button 1"
            android:textSize="25dp"
            android:textStyle="bold" />

    </LinearLayout>



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

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

        <application
            android:allowBackup="true"
            android:icon="@drawable/ic_launcher"
            android:label="@string/app_name"
            android:theme="@style/AppTheme" >
            <activity
                android:name="com.pooks.thebasics.main"
                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.pooks.thebasics.menu"
                android:label="@string/app_name" >
                <intent-filter>
                    <action android:name="com.pooks.thebasics.MENU" />

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

    </manifest>

The code may not be the best code. But it was working at one point. When I put it all together, thats when it started to crash. Again, any help would be appreciated.

4

2 回答 2

0

I found my mistakes. I had various inconsistencies. When I fixed the inconsistencies I got it to work. Second, I remembered what I was doing. The first activity only comes up when the app is started. IF I open it for the first time and then click the home button the app is still open, just in the background. It was a logic error, thankfully- syntax errors are a pain!

于 2013-07-14T02:31:32.143 回答
0

If you want to start your second activity after some specific time, then why use sleep? You can use Timer to achieve the same. Also, you intent creation is wrong. You need to give the parent context which is trying to spawn a new activity.

Try this:

new Timer().schedule(new TimerTask() {

    @Override
    public void run() {
        // TODO Auto-generated method stub
        Intent menuIntent = new Intent(Main.this, menu.class);
        startActivity(menuIntent);
    }
}, 5000);
于 2013-07-14T05:47:37.250 回答