Hello,
Welcome to our Microsoft Q&A platform!
To achieve this navigation style, try setting the LaunchMode
to SingleTask
. In SingleTask
mode, there can be only one instance of an Activity in the stack. If there are already other activity instances in the stack, starting this Activity in other activities will directly kick other activity instances out of the stack.
If you set the MainActivity as the main launcher, clicking the back button in the SettingActivity will always go back to MainActivity. And clicking the back button in MainActivity will close the application.
[Activity(Label = "@string/app_name", Theme = "@style/AppTheme", MainLauncher = true, LaunchMode = LaunchMode.SingleTask)]
public class MainActivity : AppCompatActivity
{
...
private void Button_Click(object sender, EventArgs e)
{
StartActivity(new Intent(this, typeof(SettingActivity)));
}
}
[Activity(Label = "SettingActivity", LaunchMode = LaunchMode.SingleTask)]
public class SettingActivity : AppCompatActivity
{
...
private void Button_Click(object sender, EventArgs e)
{
StartActivity(new Intent(this, typeof(MainActivity)));
}
}
Best Regards,
Jarvan Zhang
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.