Instance of a Java class is not getting null on application close in android -


i have class defined

public class apimanager {     private static apimanager minstance;     public static synchronized apimanager getinstance()     {         return minstance;     }      public apimanager(context mcontext)     {         this.mcontext = mcontext;         minstance = this;     } } 

my splashactivity defined as

public class splashactivity extends baseactivity {     private string gcmregid;     private googlecloudmessaging gcm;      @override     protected void oncreate(bundle savedinstancestate)     {         super.oncreate(savedinstancestate);          notificationmanager notificationmanager = (notificationmanager)getsystemservice(notification_service);         notificationmanager.cancelall();          try {             if(apimanager.getinstance() != null)             {                 /* activity present. need move main activity */                 finish();                 intent = new intent(this, mainactivity.class);                 i.addflags(intent.flag_activity_clear_top);                 i.addflags(intent.flag_activity_clear_task);                 i.addflags(intent.flag_activity_new_task);                 startactivity(i);                 return;             }         }         catch (exception e1)         {         } 

my mainactivity ondestroy defined as

@override     public void onbackpressed()     {         if(isfullscreen)         {             animatefullscreenclose();             if (mainmapfragment.postlayout.getvisibility() == view.visible)                 mainmapfragment.closepindetails();         }         else         {             myapplication.getinstance().disconnectgoogleapi();             socketmanager.getinstance().closeconnection();             finish();             myapplication.getinstance().stopservice();         }     } } 

when press button. should stop. application closes.

however when open application again using launcher icon on android main menu, if(apimanager.getinstance() != null) fails consider null , instead of splash ended on mainactivity,

why apimanager.getinstance() not null if application closed.

static object per process. u close activity u didnt close process therefore there still value in apimanager.getinstance in order clear value , return splash screen again, clear object manually @ ondestroy of mainactivity

ondestroy(){ apimanager.clear(); }

public static void clear(){ if (minstance != null){ minstance = null; }


Comments

Popular posts from this blog

How to connect android app to App engine -

gcc - MinGW's ld cannot perform PE operations on non PE output file -

php - display validation error message next to the textbox in codeigniter -