我创建了四个活动,所有这些活动都以旗帜REORDER_TO_FRONT
打开。
请帮我解决这个问题。
请在下面找到我的四个活动 的 MainACtivity:
public class MainActivity : AppCompatActivity
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.Main);
var textView = this.FindViewById<TextView>(Resource.Id.textView);
textView.Text = "A";
textView.Click += TextView_Click;
}
private void TextView_Click(object sender, EventArgs e)
{
var intent = new Intent(this, typeof(ActivityB));
intent.SetFlags(ActivityFlags.ReorderToFront);
this.StartActivity(intent);
}
}
ACtivityB:
public class ActivityB : AppCompatActivity
{
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
SetContentView(Resource.Layout.Main);
var textView = this.FindViewById<TextView>(Resource.Id.textView);
textView.Text = "B";
textView.Click += TextView_Click;
}
private void TextView_Click(object sender, EventArgs e)
{
var intent = new Intent(this, typeof(ActivityC));
intent.SetFlags( ActivityFlags.ReorderToFront);
this.StartActivity(intent);
}
}
ActivityC :
public class ActivityC : AppCompatActivity
{
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
SetContentView(Resource.Layout.Main);
var textView = this.FindViewById<TextView>(Resource.Id.textView);
textView.Text = "C";
textView.Click += TextView_Click;
}
private void TextView_Click(object sender, EventArgs e)
{
var intent = new Intent(this, typeof(ActivityD));
intent.SetFlags( ActivityFlags.ReorderToFront);
this.StartActivity(intent);
}
}
ActivityD:
public class ActivityD : AppCompatActivity
{
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
SetContentView(Resource.Layout.Main);
var textView = this.FindViewById<TextView>(Resource.Id.textView);
textView.Text = "D";
textView.Click += TextView_Click;
}
private void TextView_Click(object sender, EventArgs e)
{
var intent = new Intent(this, typeof(MainActivity));
intent.SetFlags( ActivityFlags.ReorderToFront);
this.StartActivity(intent);
}
}
答案 0 :(得分:0)
活动有四种启动模式。它们是:
标准
singleTop
singleTask
singleInstance
更多参考资料: https://android.jlelse.eu/android-activity-launch-mode-e0df1aa72242
了解启动模式,然后就可以实现。