活动无缘无故开始

时间:2013-12-24 22:42:29

标签: java android xml android-activity

public class NinthScreen extends Activity{

    Button result;
    EditText number;

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

        result = (Button) findViewById(R.id.bReveal);
        number = (EditText) findViewById(R.id.etMagicNumber);

        result.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                Intent i = new Intent("com.example.MindReader.TenthScreen");
                Bundle b = new Bundle();
                b.putString("n", number.getText().toString());
                i.putExtras(b);
                startActivity(i);

                InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromInputMethod(number.getWindowToken(), 0);
            }
        });

    }
}

我无法看到我的代码中出现了什么问题以及为什么它没有启动下一类活动以及为什么应用程序崩溃,请帮忙!?

2 个答案:

答案 0 :(得分:0)

替换

Intent i = new Intent("com.example.MindReader.TenthScreen");

Intent i = new Intent(this, TenthScreen.class);

答案 1 :(得分:0)

首先,你想要去'AndroidManifest.xml' 并在MainActivity活动

之后添加以下行
<activity
    android:name="com.example.controller.NinthScreen"
    android:configChanges="orientation|keyboardHidden|screenSize"
    android:label="@string/app_name"
    android:theme="@style/FullscreenTheme" >
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />

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

- 注意:代替com.example.controller,包含您自己的包位置(滚动到活动代码文档的顶部)   - 注意:使用android.intent。适合您的活动的操作和类别,请查看here

完整的xml应该看起来像这样

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

    <uses-sdk
        android:minSdkVersion="9"
        android:targetSdkVersion="18" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.controller.FullscreenActivity"
            android:configChanges="orientation|keyboardHidden|screenSize"
            android:label="@string/app_name"
            android:theme="@style/FullscreenTheme" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name="com.example.controller.NinthScreen"
            android:configChanges="orientation|keyboardHidden|screenSize"
            android:label="@string/app_name"
            android:theme="@style/FullscreenTheme" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

</manifest>

尝试此操作,如果不起作用,请再次发布。