Android 返回到不同的父活动
我目前只能返回到一个父活动,这是我的启动页面。我正在使用标题栏(左上角)上的“后退”按钮。我想启用“后退”按钮以返回到上一页,而不是直接返回到启动页(无论如何,返回之前都有一个白色屏幕) 我试过下面的代码,我的启动页面是Aucon,对于一些活动,我想返回的页面是SignIn页面,但我不能。我的代码有什么问题吗?或者它自然不允许?请给我一些建议Android 返回到不同的父活动,android,android-activity,parent,Android,Android Activity,Parent,我目前只能返回到一个父活动,这是我的启动页面。我正在使用标题栏(左上角)上的“后退”按钮。我想启用“后退”按钮以返回到上一页,而不是直接返回到启动页(无论如何,返回之前都有一个白色屏幕) 我试过下面的代码,我的启动页面是Aucon,对于一些活动,我想返回的页面是SignIn页面,但我不能。我的代码有什么问题吗?或者它自然不允许?请给我一些建议 <application android:allowBackup="true" android:icon="@mipmap/ic_l
<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=".AucOn">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category
android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Register"
android:label="Register"
android:parentActivityName=".AucOn" />
<activity
android:name=".SignIn"
android:label="Home"
android:parentActivityName=".AucOn" />
<activity
android:name=".BuyerHome"
android:label="Buyer Home"
android:parentActivityName=".SignIn" />
<activity
android:name=".Instructions"
android:label="Instructions"
android:parentActivityName=".AucOn" />
<activity
android:name=".CustomerSupport"
android:label="Customer Support"
android:parentActivityName=".AucOn" />
<activity android:name=".ForgotPassword"
android:label="Forgot Password"
android:parentActivityName=".AucOn" />
<meta-data
android:name="preloaded_fonts"
android:resource="@array/preloaded_fonts" />
</application>
尝试使用
OnBackPressed()
覆盖方法。它将带您进入上一屏幕
YourBackButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
onBackPressed();
}
});
我希望这能起作用。根据我所看到的,我认为您希望在某些活动中在Android上实现后退按钮,而不是转到
AucOn
活动。如果我是对的,那么您可以覆盖所需活动中的onBackPressed()
方法,并按如下方式打开sign
活动:
@Override
public void onBackPressed() {
startActivity(new Intent(CurrentActivity.this, SignIn.class);
}
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(CurrentActivity.this, SignIn.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
}
});
这将指示活动在Android上查找真正的后退按钮并打开所需的活动。现在,对于工具栏上的“后退”按钮,您必须设置如下导航单击侦听器:
@Override
public void onBackPressed() {
startActivity(new Intent(CurrentActivity.this, SignIn.class);
}
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(CurrentActivity.this, SignIn.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
}
});
这将为工具栏返回按钮单击添加单击侦听器。您是否能够从BuyerHome返回登录。如果你可以,那么我没有得到你的问题。不,我不能,是的,这就是我遇到的问题。对于低于16的API级别,我们需要在该活动中添加元数据。检查。嗨,不过没什么变化。它还是不能表演,真奇怪。请从活动“登录”中删除android:parentActivityName=“.AucOn”并检查发生了什么。嗨,我不知道如何调用我的工具栏返回按钮。你能帮忙吗?在工具栏上设置导航onClick监听器,我已经在答案中添加了它。你试过了吗,如果它有效,请接受我的答案作为有效答案。