![](/img/trans.png)
[英]How to debug when the app is terminated and then launched in xamarin forms using Visual Studio
[英]Debug a running android app using Xamarin for Visual Studio
當應用程序啟動時,我讓它從本地存儲加載一個列表,如果離線,或者如果有網絡連接,它將從Web服務加載此列表(然后寫入本地存儲。
我的問題是,我要調試這個,我需要完全關閉應用程序,然后重新啟動它(因此結束visual studio調試會話)
該應用程序將啟動,但是當我再次啟動應用程序時調用特定方法時,它會崩潰。 我無法弄清楚它在哪里摔倒。 並且由於不再附加調試會話,也沒有任何幫助。
奇怪的是。 我甚至嘗試在try catch塊中包裝方法調用和方法的內容(試圖弄清楚什么是錯的)並且它仍然會崩潰。
這是片段。
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塊中,應用程序仍在不斷崩潰
嘗試從命令提示符運行adb logcat
,並在應用程序崩潰時搜索致命異常。 沒有足夠的評論點,所以我正在使用答案。 對不起=)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.