我如何从主要活动中打开课程?

时间:2011-12-31 17:07:12

标签: android android-intent

我正试图用我的主要活动打开我的课程Speak2:

Intent i = new Intent("R.voice.Speak2");
startActivity(i);

这是第一项活动的完整代码:

public class recon extends Activity implements OnClickListener {

    ListView lv;
    static final int check = 2000;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.voice);
        lv = (ListView) findViewById(R.id.lvVoiceReturn);
        Button b = (Button) findViewById(R.id.bVoice);
        b.setOnClickListener(this);
    }

    public void onClick(View v) {
        Intent i = new Intent(recon.this, Speak2.class); 
        startActivity(i);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        // TODO Auto-generated method stub
        super.onActivityResult(requestCode, resultCode, data);
    }

}

我的程序很简单。该按钮出现在voice.xml布局中,按下后会启动类活动Speak2。为什么第二个活动从未显示过?

1 个答案:

答案 0 :(得分:4)

尝试这种方式并确保Activity Speak2中也定义了AndroidManifest.xml,否则您将获得例外。

// MainActivity is your main activity
Intent i = new Intent(MainActivity.this, Speak2.class); 
startActivity(i);

<application>中的AndroidManifest.xml标记应如下所示:

<application android:icon="@drawable/ic_launcher" android:label="@string/app_name" >
    <activity android:label="@string/app_name" android:name="recon" >
        <intent-filter > 
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name="Speak2" />
</application>