android - Main Activity Instance sometimes Throw Run Time Exception "LinphoneActivity not instantiated yet" -


i make application linphone library, have code throw exception in mainactivity :

private static mainactivity instance;  public static final boolean isinstanciated() {     return instance != null; }  public static final mainactivity instance() {     if (instance != null) {         return instance;     }     throw new runtimeexception("linphoneactivity not instantiated yet"); } 

method instance used in activity (incomingcallactivity , contact data activity)

incoming call activity launch if there call phone

if (!linphonemanager.getinstance().acceptcallwithparams(mcall, params)) {             // above method takes care of samsung galaxy s             toast.maketext(this, r.string.couldnt_accept_call, toast.length_long).show();         } else {             if (!mainactivity.isinstanciated()) {                 return;             }             final linphonecallparams remoteparams = mcall.getremoteparams();             if (remoteparams != null && remoteparams.getvideoenabled() && linphonemanager.getinstance().isautoacceptcamera()) {                 mainactivity.instance().startvideoactivity(mcall);             } else {                 mainactivity.instance().startincallactivity(mcall);             }         } 

contactdataactivity launch if user choose contact menu

private void docall(string number) {         log.d(tag, "try call here: " + number);         if (account.isprepaidregistered()) {             mainactivity.instance().requesttocall(number);         } else {             intent intent = new intent(contactdataactivity.this, prepaidregisteractivity.class);             startactivity(intent);         }     } 

where each of activity need call instance of mainactivity call method in mainactivity requestcall or incall.

some time when running app, logcat show :

java.lang.runtimeexception: linphoneactivity not instantiated yet

is normal, or there wrong code ?

never try instantiate activity self android framework you, if want activity singleton use lauchmodes in intent filter not singleton design pattern there plenty of tutorials on lauchmode here, here , here


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -