c# - Android Application Crash Management using Xamarin -


general scenario :

while developing android application using xamarin, tend crash application multiple times , behavior acceptable , normal.

but time, when navigate 1st activity 2nd activity. , on 2nd activity if application crashes, on next run application starts 2nd activity, should start 1st activity. please note 1st activity : mainlauncher property set true.

application :

1 st activity = splash screen;  2 nd activity = login screen; [sets global appication variable user id]  3 rd activity = user profile [fetch data database using user id];  4 th activity = preference page, settings saves username n password login form. 

==============================================================================

problem :

while running application flow should go according given activities, when enter correct credential on login page saves (int)userid. , using userid fetch details of user , display them on 3rd activity.

but times if application crashes on 3rd activity, , when restart application not starts splash screen, activity crashed(3rd activity) on or previous activity(caller of 3rd activity,not loginform) activity called.

now problem never received loginpage never entered login details (int)userid set 0/null, , no data fetched database. showing fields on 3rd activity(profile activity) blank

my handling solution:

so handle override onresume() , check userid, i.e if userid 0 load loginscreen. works fine.

but when manually exit application killing processid, still profile screen remains, calls onresume(); again. had logged out again load login screen,....

and goes on in loop. unable exit application killing processid, please me find solution problem

sorry such long question, didn't find way explain better this, hope friends won't mind.

(answered op in question edit. converted community wiki answer. see question no answers, issue solved in comments (or extended in chat) )

the op wrote:

i managed solve problem , explain simple example.

class clsmainprojectlibrary :

this main library defined function can called in of activity reuse code.

clsmainprojectlibrary {   //this variable set calling activity check if user has opt exiting     application or application has crashed.   public static bool isexit;    // global application variable assigned when user log-ins else   public static int intuserid;      public intent applicationcrashhandler(activity actform)     {       if (clsfunctionaliba.isexit == false)       {        intent intentmyfirstform = new intent(actform,typeof(actmyfistform));        intentmyfirstform.setflag(activityflags.cleartop & activityflags.newtask);        return intentmyfirstform;       }       else       {        intent blankintent = new intent();        blankintent.setflags(activityflags.cleartop);        int intpid = android.os.process.mypid();        android.os.process.killprocess(intpid);        return null;       }     }   } 

**actmycustomactivity.cs : **

this custom activity, in activity call our applicationcrashhandler(). whenever activity crashed or started default should load actmyfirstform

[activity(label = "profile details",mainlauncher=false)]  public class actmycustomactivity : activity  {    clsmainprojectlibrary objmainprojectlibrary = new clsmainprojectlibrary();    protected override void oncreate(bundle bundle)    {      // put code here... u want    }     protected override void onresume()    {     if (clsmainprojectlibrary.intuserid == 0)     {       startactivity(objmainprojectlibrary.applicationcrashhandler(this));     }     base.onresume();    }     public override bool oncreateoptionsmenu(imenu menu)    {      //here have exit menu.    }     public override bool onoptionsitemselected(imenuitem item)    {      //code user clicking on exit.      :      :      case 'exit' :                    clsfunctionaliba.isexit = true;                   int intpid = android.os.process.mypid();                   android.os.process.killprocess(intpid);       :      :    }  } 

====================================================================

** code works me...**

it checks if userid = 0 or has value, , if user has clicked on exit menu. need exit application totally without loading our required screen.

this might not best solution, or recommended solution, works me....

if there legit method problem please, let me no modify code accordingly .


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -