gpt4 book ai didi

java - 使用线程的 Intent 不起作用

转载 作者:行者123 更新时间:2023-12-01 23:43:13 25 4
gpt4 key购买 nike

我知道我已经问过这个问题,但我没有得到足够的答案。我试图启动一个 Activity ,但模拟器停留在第一个 Activity 上。我已经尝试了所有方法,但从未奏效。 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>

最佳答案

试试这个:

Intent open = new Intent(Opening.this, Menu.class);
startActivity(open);

关于java - 使用线程的 Intent 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17605448/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com