You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Android调用Intent启动Activity时应用崩溃问题排查与解决

问题分析与解决方案

嗨,作为Android新手,你遇到的这个崩溃问题其实非常常见,咱们一步步来解决:

1. 核心问题:未在AndroidManifest中注册MembraneActivity

Android系统要求所有的Activity都必须在AndroidManifest.xml中声明,否则系统找不到这个Activity,点击跳转时就会直接崩溃。你的Manifest里只注册了MainActivity,漏掉了关键的MembraneActivity声明。

修改后的AndroidManifest.xml代码:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.android.cellularbiology">
    <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <!-- 新增这行,注册MembraneActivity -->
        <activity android:name=".MembraneActivity" />
    </application>
</manifest>

2. 次要问题:activity_membrane.xml布局标签不完整

你提供的activity_membrane.xml里的LinearLayout标签缺少必要的命名空间属性,也没有正确闭合,这会导致布局解析失败,同样可能引发崩溃。

修改后的activity_membrane.xml代码:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <TextView android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Membrane Explanation Page"/>
</LinearLayout>

这里补充了LinearLayout的命名空间、宽高属性,同时把TextView的height改成wrap_content(用match_parent会占满整个屏幕,显示逻辑不太合理)。

3. Intent代码优化(可选)

你的Intent写法本身是正确的,但可以简化成更简洁的形式,功能完全一致:

public void explainCellMembrane(View view) {
    startActivity(new Intent(MainActivity.this, MembraneActivity.class));
}

验证步骤

  1. 完成上述修改后,Clean一下项目(Build -> Clean Project)
  2. 重新运行App,点击"Cell Membrane"的TextView,就能正常跳转到MembraneActivity啦!

内容的提问来源于stack exchange,提问作者Shun Long TSANG

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 06:49:44