简体   繁体   English

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

[英]Debug a running android app using Xamarin for Visual Studio

When the app starts I have it loading a list from local storage if offline, or if there is a network connection it will load this list from a web service (and then write to local storage. 当应用程序启动时,我让它从本地存储加载一个列表,如果离线,或者如果有网络连接,它将从Web服务加载此列表(然后写入本地存储。

My issue is that for me to debug this, i need to close the app completely and then restart it (therefore ending the visual studio debug session) 我的问题是,我要调试这个,我需要完全关闭应用程序,然后重新启动它(因此结束visual studio调试会话)

The app will boot but when I call a particular method once the app has started again it crashes. 该应用程序将启动,但是当我再次启动应用程序时调用特定方法时,它会崩溃。 I cant figure out where its falling over. 我无法弄清楚它在哪里摔倒。 and as the debug session is no longer attached that is no help either. 并且由于不再附加调试会话,也没有任何帮助。

Weird thing is. 奇怪的是。 I've even tried wrapping the method call and the contents of the method in a try catch block (to try and figure out whats wrong) and its still falling over. 我甚至尝试在try catch块中包装方法调用和方法的内容(试图弄清楚什么是错的)并且它仍然会崩溃。

Here is the fragment. 这是片段。

 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;
    }

And this is the method that is being called 这就是被调用的方法

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
        {                
        }
    }

Notice, I've tried putting the whole method in a try block and the app is still falling over 请注意,我已经尝试将整个方法放在try块中,应用程序仍在不断崩溃

Try running adb logcat from the command prompt and search for a fatal exception when the app crashes. 尝试从命令提示符运行adb logcat ,并在应用程序崩溃时搜索致命异常。 Haven't got enough points for a comment so i'm using the answer instead. 没有足够的评论点,所以我正在使用答案。 Sorry =) 对不起=)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在应用程序终止然后使用 Visual Studio 以 xamarin 形式启动时进行调试 - How to debug when the app is terminated and then launched in xamarin forms using Visual Studio Visual Studio无法调试Xamarin.Android应用 - Visual studio is not debuging Xamarin.Android app 如何使用 Xamarin for Visual Studio 在真实的 Android 设备上进行调试? - How do I debug on a real Android device using Xamarin for Visual Studio? Xamarin-forms Visual Studio 2015-无法调试应用 - Xamarin-forms Visual Studio 2015 - Failing to debug app Xamarin 表单,在 Visual Studio Android 模拟器上运行的应用程序但在真实设备上崩溃 - Xamarin forms, App running on Visual Studio Android Emulator But crashes on real device 如何在Visual Studio 2017中将Wikitude SDK与Xamarin组件一起使用来运行AR应用程序? - How to get a running AR app using Wikitude SDK with Xamarin Component in Visual studio 2017? Xamarin Android Visual Studio让部署覆盖应用程序 - Xamarin Android Visual Studio let deploy override app Visual Studio 2015无法调试xamarin项目 - Visual studio 2015 cannot debug xamarin project 如何使用 Visual Studio 调试 Xamarin UWP 项目 - How to debug Xamarin UWP project with Visual Studio Xamarin Visual Studio 中的 Android 模拟器不显示应用程序 - Android emulator in Xamarin Visual Studio does not show the app
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM