如何使用Visual Studio和Xamarin关闭活动android

如何使用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 ,它将按预期工作.删除以使其在按下后退"按钮时不显示的更好的方法是将该Activity的 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.

如果您具有 LoginActivity DashboardActivity ,并且您不希望在登录后按后退按钮时显示 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
{
}