以下是我的代码页:
>**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'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>
代码可能不是最好的代码。但它一度在努力。当我把它们全部放在一起时,那就是当它开始崩溃时。再次,任何帮助将不胜感激。
答案 0 :(得分:0)
我发现了自己的错误。我有各种不一致的地方。当我修复不一致时,我得到了它的工作。其次,我记得我在做什么。第一个活动仅在应用启动时出现。如果我是第一次打开它,然后单击主页按钮,应用程序仍处于打开状态,就在后台。这是一个逻辑错误,谢天谢地 - 语法错误很痛苦!
答案 1 :(得分:0)
如果您想在某个特定时间后开始第二项活动,那么为什么要使用睡眠?您可以使用Timer
来实现相同的目标。而且,你的意图创造是错误的。您需要提供尝试生成新活动的父上下文。
试试这个:
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);