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.
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)
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.
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 running adb logcat
from the command prompt and search for a fatal exception when the app crashes. Haven't got enough points for a comment so i'm using the answer instead. Sorry =)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With