活动标志FLAG_ACTIVITY_REORDER_TO_FRONT无法按预期工作

时间:2017-12-20 10:34:23

标签: android xamarin

我创建了四个活动,所有这些活动都以旗帜REORDER_TO_FRONT打开。

  • 我按此顺序打开了活动A,B,C和D
  • 现在堆叠是A - > B - > C - > d
  • 现在我再次打开活动A,堆叠为B - > C - > D - > A
  • 当我点击回来时,应用最小化而不是去D.

请帮我解决这个问题。

请在下面找到我的四个活动 的 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);
    }
}

1 个答案:

答案 0 :(得分:0)

活动有四种启动模式。它们是:

  1. 标准

  2. singleTop

  3. singleTask

  4. singleInstance

  5.   

    更多参考资料: https://android.jlelse.eu/android-activity-launch-mode-e0df1aa72242

    了解启动模式,然后就可以实现。