java - Android Change View After Certain Amount of Time -


i'm new androidstudio , having trouble finding way change views without requiring action user. more specifically, i'm trying make app display title screen when opens, switch main interface after few seconds. found code changing views current view displaymessageactivity class in android tutorials:

intent intent = new intent(this, displaymessageactivity.class); startactivity(intent); 

i tried use code in oncreate method of title screen activity such:

protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.title_screen);     try {         thread.sleep(5000);     } catch (exception e) {         e.printstacktrace();     }     intent intent = new intent(this, displaymessageactivity.class);     startactivity(intent); } 

then set second view in new activity. tried use 2 separate views in oncreate method:

protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.title_screen);     try {         thread.sleep(5000);     } catch (exception e) {         e.printstacktrace();     }     setcontentview(r.layout.main_menu); } 

however, in both cases, displays second view. going wrong?

you using same layout in both activities, fix (r.layout.....)

avoid thread.sleep block app itself. have introduce delay when calling second activity. pls refer https://www.youtube.com/watch?v=lclo7q2uhos

your following code should put in handler block time delay want

 intent intent = new intent(this, displaymessageactivity.class);     startactivity(intent); 

Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -