java - Main Activity Destroyed before Splash Screen return -
i have main activity call splash screen intent destroys after 3 seconds between lifecycle of splash screen intent main activity destroys (which wrong!).. when splash screen intent finished app crashes because main activity has been destroyed itself.
i appreciate if can me this, i'm out of ideas @ point.
here's code:
mainactivity.java
public class mainactivity extends activity { private webview webview; public mainactivity() { } @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); log.debug("oncreate(): " + savedinstancestate); myapplication.startsomemobilecore(this); myapplication.startsomemobilenotifier(this); setcontentview(r.layout.main); this.onnewintent(this.getintent()); } @override protected void onstart() { log.debug("onstart()"); super.onstart(); } @override protected void onrestart() { super.onrestart(); this.wasrestarted = true; } @override protected void onresume() { super.onresume(); } protected void onpause() { super.onpause(); this.receivedintent = false; } protected void onstop() { super.onstop(); this.receivedintent = false; } public void ondestroy() { super.ondestroy(); } @override public void onnewintent(intent intent) { log.debug("onnewintent(): " + intent); super.onnewintent(intent); if(intent == null) { log.warn("received null intent, ignore"); } if ("ok".equals(authcode)) { if (intent != null && intent.getdata() != null && ("content".equals(intent.getdata().getscheme()) || "http".equals(intent.getdata().getscheme()))) { log.debug("intent.getdata() :" + intent.getdata() + "; intent.getdata().getscheme() : " + intent.getdata().getscheme()); string requestedpath; if ("http".equals(intent.getdata().getscheme())) { requestedpath = urldecoder.decode(intent.getdata().tostring()); } else { requestedpath = intent.getdata().getpath(); } showresource(requestedpath); } else { log.debug("intent without data -> go entry page after splash screen"); showresource(configuration.properties.getproperty("portal")); } } else { intent errorintent = new intent(this, errorintent.class); startactivity(errorintent); // finish actual activity finish(); } log.debug("show splash screen"); intent intentsplash = new intent(this, splashintent.class); startactivity(intentsplash); } void showresource(string resourcetoshow) { webview = (webview)findviewbyid(r.id.browser); webview.getsettings().setrenderpriority(websettings.renderpriority.high); webview.getsettings().setcachemode(websettings.load_default); webview.setwebviewclient(new webviewclient()); webview.getsettings().setjavascriptenabled(true); webview.getsettings().setdomstorageenabled(true); webview.loadurl(resourcetoshow); } } }
here splashintent.java
public class splashintent extends activity { // time splash screen should shown (in ms) private static final int splashtime = 3000; static logger log = logger.getlogger(splashintent.class); @override public void oncreate(final bundle savedinstancestate) { log.debug("splashintent: oncreate"); super.oncreate(savedinstancestate); setcontentview(r.layout.splash); handler handler = new handler(); handler.postdelayed(new runnable() { public void run() { log.debug("splashintent: killing splash"); finish(); } }, splashtime); } } here part of logcat
there doesn't seem reason override onnewinent in mainactivity.
in oncreate() method use following:
if(savedinstancestate == null){ intent splashintent = new intent(this, splashintent.class); startactivity(splashintent); } this start splash screen whenever mainactivity initialized without saved state. since splashintent activity calls finish after done should revert last activity in stack (aka mainactivity).
an better way use splashintent activity launcher activity , forward user mainactivity using intent.
very simple example be:
public class splashintent extends activity { @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); log.debug("splashintent: oncreate"); super.oncreate(savedinstancestate); setcontentview(r.layout.splash); handler handler = new handler(); handler.postdelayed(new runnable() { public void run() { log.debug("splashintent: killing splash"); intent intent = new intent(this, mainactivity.class); startactivity(intent); finish(); } }, splashtime); } }
Comments
Post a Comment