在monodroid活动中使用process属性时出现黑屏

时间:2012-11-17 11:59:56

标签: android android-mapview xamarin.android

从一个活动我的应用程序将转到第二个活动(我在这里发送一些此活动代码)。此活动有mapview。因为我在我的应用程序中有2个mapview我应该在此活动中使用'Process'属性。但是当我在午餐前使用此属性时,活动应用程序会显示黑屏几秒钟,然后我的ProgressDialog和活动将显示。我想这个黑屏不出现

这是我班级的定义:

    [Activity (Label = "PropertyShowActivity",
           Process =":PropertyShowMapActivity")]            
public class PropertyShowActivity : MapActivity
{.....}

此活动的onCreate代码为:

protected override void OnCreate (Bundle bundle)
    {
        try {
            base.OnCreate  (bundle);

            RequestWindowFeature (WindowFeatures.NoTitle);
            PD = new ProgressDialog (this);
            PD.SetMessage ("Please Wait...");
            PD.Indeterminate = true;
            PD.SetCancelable (false);
            PD.Show ();
            currentproperty = new Property ();
            SetContentView (Resource.Layout.PropertyShow);
            mapLayout = FindViewById ,,,,<LinearLayout > (Resource .Id.PrptyLocationOnMapLayout);
            mapLayout .Visibility = ViewStates.Gone;



            if (RplSettings.Sitename == string.Empty) {
                RplSettings.LoadAllSettings (this);
            }
            action = Intent.GetStringExtra (AppConstants.Action);
            Pid = Intent.GetLongExtra ("Pid", 0);

            Common .MenuInitialize (this, "Property");
            Common .MenuEventInitialize (this);
            AssignBottomActionBarEvents ();

            FindElemnts ();

            if (Pid == 0)
                Pid = Intent.GetIntExtra ("Pid", 0);

            if (action == string.Empty) {
                PD.Hide ();
                Finish ();
            }
            if (action == AppConstants.DownloadProperty) {
                LoadPropertyData ();
            } else if (action == AppConstants.OfflineProperty) {
                OfflineProperty = true;
                //var path = Intent.GetStringExtra (AppConstants.PropertyFilePath);
                //currentproperty = IOAddOn.ParsePropertyJsonString (UTF8Encoding.UTF8.GetString (Property.LoadPropertyFromSD (path)));
                LoadPropertyData ();
            }


        } catch (Exception ex) {
            Common.HandleException (ex);
        }
    }

以及ddms的日志是: 当我定义我的类如下所示它工作正常:

[Activity (Label = "PropertyShowActivity")]         
public class PropertyShowActivity : MapActivity
{.....}

2 个答案:

答案 0 :(得分:0)

当您添加Process属性时,您告诉Android操作系统在新进程中启动该活动。加载新进程可能需要一些时间,这就是出现黑屏的原因(将其视为启动新应用程序)。不幸的是,除了优化代码之外,你无法避免这种情况(见下文)。

看来你在OnCreate()覆盖中做了很多工作,比如加载设置等。你可能想在这样的后台运行它们。

        Task.Factory.StartNew(()=>
            {
                // load settings here
                // do expensive non-ui work here

                RunOnUiThread(() =>
                    {
                        // do UI work here
                    });
            });

答案 1 :(得分:0)

我解决了它在同一个进程中运行两个应用程序。但是在进入第二个活动后,我在应用程序的应用程序类中保存了新应用程序的状态。然后当我在OnResume中返回第一个map活动时,我将mapview的状态更改为过去的状态。 它运作正常。

相关问题