活动之间转换缓慢

时间:2014-02-10 14:53:40

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

我在MWC.Android项目上工作,我建立了自己的项目,但是当我在活动之间切换时,我需要花费几秒钟的时间和GC启动。问题显示在活动之间的所有切换。所有对象列表等清除可能是我的项目设置中的问题。

从设备部署:

[AbsListView] unregisterIRListener() is called 
[AbsListView] onVisibilityChanged() is called, visibility : 0
[AbsListView] unregisterIRListener() is called 
[AbsListView] unregisterIRListener() is called 
[AbsListView] unregisterIRListener() is called 
[AbsListView] unregisterIRListener() is called 
[AbsListView] unregisterIRListener() is called 
[Mono] GC_BRIDGE num-objects 60 num_hash_entries 70 sccs size 70 init 0.00ms df1 0.24ms sort 0.03ms dfs2 0.15ms setup-cb 0.09ms free-data 0.09ms user-cb 27.86ms clenanup 0.18ms links 21/21/19/1 dfs passes 260/149
[Mono] GC_MINOR: (Nursery full) pause 5.55ms, total 5.68ms, bridge 28.47ms promoted 368K major 1344K los 0K
[Choreographer] Skipped 76 frames!  The application may be doing too much work on its main thread.
[AbsListView] unregisterIRListener() is called 
[AbsListView] unregisterIRListener() is called 
[AbsListView] unregisterIRListener() is called 
[--------] OnResume called, app is ready to interact with the user
[AbsListView] unregisterIRListener() is called 
[Mono] The request to load the assembly System.Xml v2.0.5.0 was remapped to v2.0.0.0
[Mono] Unloading image System.Xml.dll [0x7cae81d8].
[Mono] GC_BRIDGE num-objects 202 num_hash_entries 8119 sccs size 8119 init 0.00ms df1 17.58ms sort 2.99ms dfs2 7.84ms setup-cb 1.01ms free-data 6.10ms user-cb 35.55ms clenanup 0.46ms links 9462/9462/7954/4 dfs passes 18022/17709
[Mono] GC_MINOR: (Nursery full) pause 31.77ms, total 31.95ms, bridge 54.08ms promoted 864K major 2208K los 64K
[Mono] The request to load the assembly System v2.0.5.0 was remapped to v2.0.0.0
[Mono] Unloading image System.dll [0x7acf0768].
Thread started: <Thread Pool> #2
Thread started: <Thread Pool> #3
[AbsListView] unregisterIRListener() is called 
[Mono] The request to load the assembly Mono.Security v2.0.5.0 was remapped to v2.0.0.0
[Mono] Assembly Mono.Security[0x7b675248] added to domain RootDomain, ref_count=1
[Mono] AOT failed to load AOT module Mono.Security.dll.so: dlopen failed: library "/data/data/CarCatalog.CarCatalog/lib/Mono.Security.dll.so" not found
[Mono] The request to load the assembly mscorlib v2.0.5.0 was remapped to v2.0.0.0
[Mono] Unloading image mscorlib.dll [0x7c1195b8].
Loaded assembly: Mono.Security.dll [External]
[Mono] The request to load the assembly Mono.Security v2.0.5.0 was remapped to v2.0.0.0
[Mono] Unloading image Mono.Security.dll [0x7c9a7668].
[Mono] The request to load the assembly System v2.0.5.0 was remapped to v2.0.0.0
[Mono] Unloading image System.dll [0x7c9a7668].
[Mono] DllImport attempting to load: '/system/lib/libc.so'.
[Mono] DllImport loaded library '/system/lib/libc.so'.
[Mono] DllImport searching in: '/system/lib/libc.so' ('/system/lib/libc.so').
[Mono] Searching for 'uname'.
[Mono] Probing 'uname'.
[Mono] Found as 'uname'.
[Mono] DllImport attempting to load: '/system/lib/libc.so'.
[Mono] DllImport loaded library '/system/lib/libc.so'.
[Mono] DllImport searching in: '/system/lib/libc.so' ('/system/lib/libc.so').
[Mono] Searching for 'gettid'.
[Mono] Probing 'gettid'.
[Mono] Found as 'gettid'.
[Mono] GC_BRIDGE num-objects 18 num_hash_entries 24 sccs size 24 init 0.00ms df1 0.09ms sort 0.09ms dfs2 0.21ms setup-cb 0.00ms free-data 0.06ms user-cb 30.79ms clenanup 0.03ms links 9468/9468/7960/4 dfs passes 18070/17739
[Mono] GC_MINOR: (Nursery full) pause 20.20ms, total 20.35ms, bridge 31.28ms promoted 1232K major 3440K los 256K
[AbsListView] onVisibilityChanged() is called, visibility : 4
[AbsListView] unregisterIRListener() is called

我的代码示例:

    protected override void OnCreate(Bundle bundle)
    {
        //CMobApp.LogDebug("CARS OnCreate");
        base.OnCreate(bundle);

        // set our layout to be the home screen
        SetContentView(Resource.Layout.ContentLayout);

        //Top left menu btn
        tittle = FindViewById<TextView> (Resource.Id.textView1);
        selectCar = FindViewById<TextView> (Resource.Id.textView2);

        Typeface tf = Typeface.CreateFromAsset (this.Assets, "fonts/ProximaNova-Regular.otf");

        tittle.SetTypeface (tf, TypefaceStyle.Normal);
        selectCar.SetTypeface (tf, TypefaceStyle.Normal);
        //spinnerText.SetTypeface (tf, TypefaceStyle.Normal);
        //Find our controls
        carListView = FindViewById<ListView>(Resource.Id.CarList);
        makeSpinner = FindViewById<Spinner> (Resource.Id.MakeSpinner);
        modelSpinner = FindViewById<Spinner> (Resource.Id.ModelSpinner);
        versionSpinner = FindViewById<Spinner> (Resource.Id.VersionSpinner);
        //Nowy spinner: GENERACJA
        generationSpinner = FindViewById<Spinner> (Resource.Id.TypeSpinner);
        ImageButton favouriteButton = FindViewById<ImageButton> (Resource.Id.favouriteButton);
        //var gallery = FindViewById<ImageButton> (Resource.Id.gallery);
        //var menu = FindViewById<FlyOutContainer> (Resource.Id.FlyOutContainer);
        //var menuButton = FindViewById (Resource.Id.MenuButton);
        favouriteButton.Click += (sender, e) => {
            Intent intent = new Intent();
            intent.SetClass(this, typeof(FavoritesScreen));
            intent.AddFlags(ActivityFlags.ClearTop);            // http://developer.android.com/reference/android/content/Intent.html#FLAG_ACTIVITY_CLEAR_TOP
            StartActivity(intent);
        };


        generationSpinner.Visibility = ViewStates.Gone;
        InitMakeSpinner ();

        InitModelSpinner ();

        InitVersionSpinner ();

        InitGenerationSpinner ();




        // wire up task click handler
        if (carListView != null) {
            carListView.ItemClick += (object sender, AdapterView.ItemClickEventArgs e) => {

                var carDetails = new Intent(this, typeof(CarDetailsScreen));
                carDetails.PutExtra("CarID", cars[e.Position].ID);
                StartActivity(carDetails);

            };
        }
    }


    //NEW Adding generation:
    void InitGenerationSpinner () {



        generationSpinner.Enabled = true; 
        generationSpinner.ItemSelected += (object sender, AdapterView.ItemSelectedEventArgs e) => {
            selectedGeneration = generation [e.Position];
            RunOnUiThread (() => {
                UpdateGenerationSpinner();  

                UpdateCarList ();
                selectedGeneration = null;
            });
        };


    }



    void InitVersionSpinner () {
        //versionSpinner.Enabled = false;
        versionSpinner.ItemSelected += (object sender, AdapterView.ItemSelectedEventArgs e) => {
            selectedVersion = versions [e.Position];
            RunOnUiThread (() =>  {
                UpdateCarList ();
                UpdateGenerationSpinner();
            });
        };
    }

    void InitModelSpinner ()
    {
        modelSpinner.Enabled = false;
        modelSpinner.ItemSelected += (object sender, AdapterView.ItemSelectedEventArgs e) =>  {
            selectedModel = models [e.Position];
            RunOnUiThread (() =>  {
                UpdateVersionSpinner();
                UpdateCarList ();
            });
        };
    }



    void InitMakeSpinner ()
    {
        makes = MakeManager.GetMakes ();
        if (makes.Count != 0) {
            selectedMake = makes [2];
            ArrayAdapter<Make> makesArrayAdapter = new ArrayAdapter<Make> (this, Resource.Layout.SpinnerText, makes);
            makesArrayAdapter.SetDropDownViewResource (Resource.Layout.row_spinner); 

            makeSpinner.Adapter = makesArrayAdapter;
            makeSpinner.Visibility = Android.Views.ViewStates.Visible;
            makeSpinner.SetSelection (2);
            makeSpinner.ItemSelected += (object sender, AdapterView.ItemSelectedEventArgs e) => {
                selectedMake = makes [e.Position];              
                RunOnUiThread (() => {
                    UpdateModelSpinner ();
                    UpdateCarList ();
                });

            };
        } else {
            makeSpinner.Visibility = Android.Views.ViewStates.Invisible;
            Android.Util.Log.Info ("CarsScreen.cs", "MakeManager count 0");
        }
    }

    protected void UpdateCarList() {

        if (selectedModel!=null && selectedVersion!=null && selectedGeneration == null) {
            //cars.Clear ();
            cars = CMob.BL.Managers.CarManager.GetCars(selectedModel, selectedVersion);     

        } else if (selectedModel!=null && selectedVersion!=null && selectedGeneration!=null) {
            //cars.Clear ();
            cars = CMob.BL.Managers.CarManager.GetCars(selectedModel, selectedVersion,selectedGeneration);      

        } else if (selectedModel!=null) {
            //cars.Clear ();
            cars = CMob.BL.Managers.CarManager.GetCars(selectedModel);  

        } 
        else if (selectedMake!=null) {
            //cars.Clear ();
            cars = CMob.BL.Managers.CarManager.GetCars(selectedMake);
        } 
        else if(selectedGeneration!=null){
            //  cars.Clear ();
            cars = CMob.BL.Managers.CarManager.GetCars(selectedGeneration);
        }

        carListView.Adapter = new CMob.Adapters.CarListAdapter(this, cars); 



    }

    protected void UpdateModelSpinner() {       
        if (selectedMake != null) {

            models = ModelManager.GetModels(selectedMake);

            modelsArrayAdapter = new ArrayAdapter<Model> (this, Resource.Layout.SpinnerText , models);
            modelsArrayAdapter.SetDropDownViewResource (Resource.Layout.row_spinner); 
            modelSpinner.Adapter = modelsArrayAdapter;
            if (models.Count > 0) {
                modelSpinner.Enabled = true;
            } else {

                modelSpinner.Enabled = false;
            }

        }
    }

    protected void UpdateVersionSpinner() {     
        if (selectedModel !=  null) {

            versions = VersionGeneralManager.GetFilteredVersions((List<Car>)CMob.BL.Managers.CarManager.GetCars(selectedModel));
            ArrayAdapter<VersionGeneral> versionAdapter = new ArrayAdapter<VersionGeneral> (this, Resource.Layout.SpinnerText , versions);
            versionAdapter.SetDropDownViewResource (Resource.Layout.row_spinner); 
            versionSpinner.Adapter = versionAdapter;
            if(versions.Count>0) 
                versionSpinner.Enabled = true; 
            else 
                versionSpinner.Enabled = false;
        }
    }

    //Generation spinner:

    protected void UpdateGenerationSpinner() {      
        if (selectedVersion !=  null) {

            generation = BL.Managers.GenerationManager.GetGenerations(selectedModel);

            ArrayAdapter<Generation> genAdapter = new ArrayAdapter<Generation> (this, Resource.Layout.SpinnerText , generation);
            genAdapter.SetDropDownViewResource (Resource.Layout.row_spinner); 


            generationSpinner.Adapter = genAdapter;
            if (generation.Count > 0) {

                generationSpinner.Enabled = true; 
                generationSpinner.Visibility = ViewStates.Visible;

            }else {

                generationSpinner.Enabled = false; 
                generationSpinner.Visibility = ViewStates.Gone;

            }
    }
    }



    public int getMake(){
        return selectedMake.ID;
    }

    public string getMakeText(){
        return selectedMake.Makename;
    }

    public string getModelText(){
        return selectedModel.Modelname;
    }
    public string getGenerationText(){
        return selectedGeneration.Generationname;
    }
    public int getScreenType(){
        return 0;
    }

    protected override void OnResume()
    {   UpdateCarList ();
        Log.Debug ("--------", "OnResume called, app is ready to interact with the user");
        base.OnResume();
    }


}

}

0 个答案:

没有答案