从活动中删除所有视图

时间:2015-09-08 20:05:57

标签: c# android android-activity view xamarin.forms

我使用方法AddContentView在Activity中添加我的视图:

protected override void OnCreate (Bundle bundle)
{
    base.OnCreate (bundle);
    global::Xamarin.Forms.Forms.Init (this, bundle);
    LoadApplication (new App());
    this.AddContentView (myView, layoutPararms);
}

protected override void OnBackPressed ()
{
    this.RemoveAllViews() //this method does not contain in Activity
}

我按下“后退”按钮并多次打开我的应用程序。 内存溢出是因为我每次在OnCreate方法中都在Activity中添加视图。 如何从活动中删除所有视图?

1 个答案:

答案 0 :(得分:0)

您不在OnCreate中使用AddContentView,因为LoadApplication已经使用。