我知道我已经问过了,但我没有得到足够的答案。我试图开始一项活动,但模拟器停留在第一个活动上。我已经尝试了所有方法来做到这一点,但它从来没有奏效。youtube 视频显示它应该可以工作,但它永远不会。以下代码是否缺少某些内容或有什么问题?
//First Activity:
package com.mtprogramming.magicsquaresgame;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.content.Intent;
public class Opening extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_opening);
Thread timer = new Thread(){
public void run(){
try{
sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}finally{
Intent open = new Intent("com.mtprogramming.magicsquaresgame.MENU");
startActivity(open);
}
}
};
timer.start();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.opening, menu);
return true;
}
}
//Second Activity:
package com.mtprogramming.magicsquaresgame;
import android.app.Activity;
import android.os.Bundle;
//Created by suprav on 7/11/13.
public class Menu extends Activity {
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_menu);
}
}
//Android Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mtprogramming.magicsquaresgame"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="7"
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.mtprogramming.magicsquaresgame.Opening"
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.mtprogramming.magicsquaresgame.Menu"
android:label="@string/title_activity_menu"
android:parentActivityName="Opening" >
<intent-filter>
<action android:name="com.mtprogramming.magicsquaresgame.MENU"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="Opening" />
</activity>
</application>
</manifest>