所以我一直在开发我的第一个应用程序,除了后退按钮外,一切都很顺利。
当你按下它时会做后面的动画,但它会落在同一个Activity上然后关闭。
我想要它,所以当你按下它时会进入主Activity(第一个(开始菜单))
在我的代码中你可以知道我尝试添加noHistory = true但是它也没有用。
这是它的样子
以下是(问题2)的代码,如果给我一个问题,你可以看到
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
namespace TestingFixes
{
[Activity(Label = "firstQ", NoHistory =true)]
public class firstQ : Activity
{
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
SetContentView(Resource.Layout.firstQDesign); // Change This
Button easyBtn3 = FindViewById<Button>(Resource.Id.oopBtn); //Change This
easyBtn3.Click += (object sender, EventArgs e) => { //Change This
easyBtn3.Click += delegate { //Change This
StartActivity(typeof(easySecondQ)); //Change This
SetContentView(Resource.Layout.easysecondQDesign); //Change This
//Would I maybe connect the text here to an int?
};
};
}
}
}
这是mainACtivity(开始菜单)的代码
using System;
using Android.App;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;
namespace TestingFixes
{
[Activity(Label = "TestingFixes", MainLauncher = true, Icon = "@drawable/icon")]
public class MainActivity : Activity
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.Main);
Button easyBtn2 = FindViewById<Button>(Resource.Id.easyBtn);
easyBtn2.Click += (object sender, EventArgs e) => {
easyBtn2.Click += delegate {
StartActivity(typeof(firstQ));
SetContentView(Resource.Layout.firstQDesign);
//Would I maybe connect the text here to an int?
};
};
}
}
}
答案 0 :(得分:0)
您可以自定义Activity的 @Override
public void onBackPressed() {
if(condition)
super.onBackPressed(); // this close app
else
// your code to open MainActivity
}