当前位置: 代码迷 >> Android >> startActivity(intent);失败:进程意外停止,该怎么解决
  详细解决方案

startActivity(intent);失败:进程意外停止,该怎么解决

热度:62   发布时间:2016-04-28 06:42:30.0
startActivity(intent);失败:进程意外停止
本帖最后由 sling2007 于 2014-03-07 15:02:57 编辑
Hi,开始写android例子,测试在两个activity之间,用intent跳转的时候,发现startActivity(intent)这个句子总是失败。
想实现从MainActivity带参数跳转到SubActivity,配置如下,请各位大虾点一下啊:
MainActivity.java

public class MainActivity extends Activity implements OnClickListener {
Button submit;
TextView view1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
submit = (Button) this.findViewById(R.id.submit);
view1 = (TextView) this.findViewById(R.id.view1);
submit.setOnClickListener(this);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public void onClick(View v) {
Intent intent = new Intent();
intent.setClass(MainActivity.this, SubActivity.class);// 从哪里来,到哪里去
intent.putExtra("view1", view1.getText());
intent.putExtra("view11", view1.getText() + "1123");
                startActivity(intent);//注释掉这里,不会报错。所以应该是这里出错了
}
}


AndroidManifest.xml

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

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

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".MainActivity"
            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=".SubActivity"
            android:label="@string/app_name" />
    </application>
</manifest>


activity_main.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="50dp" >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="name: " />

        <TextView
            android:id="@+id/view1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="张三丰" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="70dp" >

        <Button
  相关解决方案