c# - 使用 Xamarin for Visual Studio 调试正在运行的 Android 应用程序

标签 c# visual-studio xamarin

当应用程序启动时,如果离线,我让它从本地存储加载一个列表,或者如果有网络连接,它将从网络服务加载这个列表(然后写入本地存储。

我的问题是,为了调试它,我需要完全关闭应用程序然后重新启动它(因此结束 visual studio 调试 session )

该应用程序将启动,但是当我在应用程序再次启动后调用特定方法时它崩溃了。我不知道它是从哪里掉下来的。由于不再附加调试 session ,这也无济于事。

奇怪的是。我什至尝试将方法调用和方法的内容包装在一个 try catch block 中(试图找出问题所在),但它仍然失败。

这是片段。

 class MyCouncilsFragment:Fragment
{
    public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
    {
        //my councils
        base.OnCreateView(inflater, container, savedInstanceState);
        var view = this.View ?? inflater.Inflate(Resource.Layout.mycouncils, container, false);
        string councils = GoIO.LoadText(CC.FILE_MYCOUNCILS) ?? "";
        List<Council> mycouncils = Shared.Serialization.Deserialize<List<Shared.Council>>(councils) ?? new List<Council>();
        MyGlobals.myCouncilsList = mycouncils;


        Spinner spncouncils = view.FindViewById<Spinner>(Resource.Id.spnCouncils);           

        if(mycouncils.Count > 0)
        {
            spncouncils.Enabled = true;
            CouncilSpinnerAdapter adapter = new CouncilSpinnerAdapter(Main_Act.context, Resource.Layout.spn_row_text, MyGlobals.myCouncilsList.ToArray());
            spncouncils.Adapter = adapter;

            Button btnSelect = view.FindViewById<Button>(Resource.Id.btnSelect);

            btnSelect.Enabled = true;
            btnSelect.Click += delegate
            {                   
                Council sessionCouncil = MyGlobals.myCouncilsList[spncouncils.SelectedItemPosition];
                //sessionCouncil is not the problem, i've tested that

                try
                {
                    Main_Act.loadLists();
                    //the issue is when this method is called. (however the call works fine when calling it from a different fragment thats basically in the same state)
                }
                catch
                {                        
                }
                //List<Designer> x = Shared.WebServerHelper.WebCall<Designer>("https://" + MyGlobals.sessionCouncil.service_url + "/design/");
                //MyGlobals.sessionColours = x[0];
                //MyGlobals.hintText = MyGlobals.getSubtleColour(MyGlobals.getColor(MyGlobals.sessionColours.controlcolour), 20);

                //var intent = new Intent(this.Activity, typeof(MyDetails_Act));
                //StartActivity(intent);                    
            };

        }
        else
        {
            //List<Council> emptylist = new List<Council>();

            //Council empty = new Council();
            //empty.council_name = "no councils added";
            //emptylist.Add(empty);

            //spncouncils.Enabled = false;

            //Button viewall = view.FindViewById<Button>(Resource.Id.btnSelect);
            //viewall.Visibility = ViewStates.Gone;

            //TextView nb = view.FindViewById<TextView>(Resource.Id.nb);
            //nb.Visibility = ViewStates.Visible;


        }



        return view;
    }

这是被调用的方法

public static void loadLists()
    {
        try
        {
            //        //  _|          _|_|      _|_|    _|_|_|    
            //        //  _|        _|    _|  _|    _|  _|    _|  
            //        //  _|        _|    _|  _|_|_|_|  _|    _|  
            //        //  _|        _|    _|  _|    _|  _|    _|  
            //        //  _|_|_|_|    _|_|    _|    _|  _|_|_|  


            if (MyGlobals.sessionCouncil != null)
            {
                var connectivityManager = (ConnectivityManager)context.GetSystemService(ConnectivityService);
                var activeConnection = connectivityManager.ActiveNetworkInfo;

                if (activeConnection != null && activeConnection.IsConnected)
                {
                    loadConsentsFromWeb();
                    Console.WriteLine("getting inspectiontypes online");
                    loadInspectionTypesOnline();
                }
                else
                {
                    try
                    {
                        loadConsentsFromFile();
                        loadInspectionTypesOffline();
                    }
                    catch
                    {
                        Toast.MakeText(context, "Unable to load consents from file", ToastLength.Long).Show();

                    }

                }

                try
                {
                    loadBookings();
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                }
            }

            else
            {
                //inspection types failed to load from file or from web. propmt user to reaload app? or something?           
                Toast.MakeText(context, "Definition Elements failed to load, please restart the app", ToastLength.Short).Show();

                System.Environment.Exit(0);
            }
        }
        catch
        {                
        }
    }

请注意,我已尝试将整个方法放在一个 try block 中,但应用程序仍在崩溃

最佳答案

尝试从命令提示符运行 adb logcat 并在应用程序崩溃时搜索致命异常。没有足够的评论积分,所以我改用答案。抱歉 =)

关于c# - 使用 Xamarin for Visual Studio 调试正在运行的 Android 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28142647/

相关文章:

c# - 如何传入特定类的方法名作为另一个方法的参数

c# - 附加属性更改事件?

visual-studio - RAD Studio XE2 的 Visual Studio WordLight 插件的等效项

Xamarin 共享库和 PCL

android - 如何将通知按钮设置为图标而不是文字

c# - SpreadsheetGear CopyFromDataTable 单元格格式

c# - 在 Unity 中创建程序网格生成器时出现尺寸问题

c# - 一种在监 window 口中获取对象并将其设为 "Script"的方法

.net - Visual Studio,测试资源管理器启动单元测试很慢

xamarin - 无法在 Visual Studio 2015 上设置 Android SDK