首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Android:返回导航到尚未调用的活动

Android:返回导航到尚未调用的活动
EN

Stack Overflow用户
提问于 2018-06-04 04:43:35
回答 1查看 43关注 0票数 0

我有一个Activity A,它在应用程序启动时显示。

活动A通过意图调用活动B

Activity B有一个工具栏,其中定义了back/home导航按钮。

在AndroidManifest中,定义了活动B的父活动是活动C

但是,当触摸后退导航按钮时,应用程序将终止,而不是显示活动C。有什么办法可以解决这个问题吗?

AndroidManifest.xml

代码语言:javascript
运行
复制
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="test.com.testlauncher">

    <application
        android:theme="@style/Theme.AppCompat.Light.NoActionBar">

        <activity android:name=".C">
        </activity>


        <activity android:name=".A" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
        </activity>

        <activity android:name=".B"
            android:parentActivityName=".C">

            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value="test.com.testlauncher.C" />
        </activity>

    </application>

</manifest>

B.java

代码语言:javascript
运行
复制
public class B extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.B);

        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_main);
        setSupportActionBar(toolbar);

        ActionBar actionBar = getSupportActionBar();

        actionBar.setTitle("Back");

        actionBar.setDisplayHomeAsUpEnabled(true);
        actionBar.setDisplayShowHomeEnabled(true);

    }
}

B.xml

代码语言:javascript
运行
复制
<?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"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar_main"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        android:elevation="0dp"
        android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>

</LinearLayout>
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50670796

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档