如何使用 Visual Studio 和 xamarin 关闭 android 活动 [英] how to close activity android using visual studio and xamarin

查看:30
本文介绍了如何使用 Visual Studio 和 xamarin 关闭 android 活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目有登录、注册和主页.我使用 StartActivity(typeof(Register)); 打开注册页面.当用户已经插入数据并单击注册按钮时,我使用 StartActivity(typeof(MainActivity)); 再次返回登录页面.当我点击手机上的后退按钮时,它返回到注册页面>登录页面>然后退出.我希望在打开新页面后关闭已创建的活动.

i have login, register, and home page on my project. I use StartActivity(typeof(Register));to open register page. When user already insert data and click register button, i use StartActivity(typeof(MainActivity)); to go back to login page again. When i click back button on my phone it back to register page>login page>then exit. I want my activity that already created is closed after i open a new page.

我的第二个问题,我有退出按钮,如何使用退出按钮关闭我的应用程序?

And my second question, i have exit button, how to close my app using the exit button?

我正在使用 Visual Studio 2015 和 Xamarin 来开发 Android 应用程序.

I'm using Visual Studio 2015 and Xamarin for developing android app.

推荐答案

调用 Finish 将关闭并终止 Activity 并且它会按预期工作.删除 Avtivity 以便在按下后退按钮时它不会出现的更好方法是将该活动的 NoHistory 设置为 true.

Calling Finish will close and kill the Activity and it will work as expected. Better way to remove an Avtivity so that it won't appear when Back button is pressed will be to set the NoHistory of that Activity as true.

如果您有 LoginActivityDashboardActivity,并且您不希望 LoginActivity 在登录后按后退按钮显示, 您可以将 LoginActivity 的 NoHistory 设置为 true,如下所示.

If you have a LoginActivity and a DashboardActivity and you don't want the LoginActivity to show while pressing back-button after logging in, you can set NoHistory of LoginActivity as true, like below.

[Activity (NoHistory = true)]
public class LoginActivity : Activity
{
}

这篇关于如何使用 Visual Studio 和 xamarin 关闭 android 活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆