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

查看:164
本文介绍了如何使用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
{
}

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

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