我一直在从 android 开发者网站学习我的应用程序。我输入它,然后当我点击发送时它强制关闭。这是我的一些有问题的代码。这是从应用程序首次显示到我点击发送按钮的活动:
package gov.gforce.myapp;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
public class MyFirstAppActivity extends Activity {
public final static String EXTRA_MESSAGE = "gov.gforce.myapp.MESSAGE";
/** Called when the activity is first created */
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
public void sendMessage(View view) {
/** Called when the user selects the Send button*/
Intent intent = new Intent(this, DisplayMessageActivity.class);
EditText editText = (EditText) findViewById (R.id.edit_message);
String message = editText.getText().toString();
intent.putExtra(EXTRA_MESSAGE, message);
startActivity(intent);
这是按下按钮后显示屏上的活动:
public class DisplayMessageActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
Intent intent = getIntent();
String message = intent.getStringExtra(MyFirstAppActivity.EXTRA_MESSAGE);{
}
// Create the text view
TextView textView = new TextView(this);
textView.setTextSize(40);
textView.setText(message);
setContentView(textView);
这是我的应用清单:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="gov.gforce.myapp"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="10" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:name=".MyFirstAppActivity"
android:label="@string/app_name" >
<activity android:name="gov.gforce.myapp.DisplayMessageActivity"/>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>