java - Android : How to load an activity faster when calling it from another activity, even while loading several contents in the second activity -
i'm new java , android asking these kind of questions here understand how should work.
i have 2 activities in app viz welcome_activity.java
, content_activity.java
the first activity work smoothly problem comes when content_activity(second activity)
called welcome_activity(first activity)
in oncreate
of second activity
, think contents many cause activity load slow.
how solve issue?
example :
@override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_puzzle_game); q1_tv = (textview) findviewbyid(r.id.q1_tv); q2_tv = (textview) findviewbyid(r.id.q2_tv); q3_tv = (textview) findviewbyid(r.id.q3_tv); q4_tv = (textview) findviewbyid(r.id.q4_tv); q5_tv = (textview) findviewbyid(r.id.q5_tv); q6_tv = (textview) findviewbyid(r.id.q6_tv); q7_tv = (textview) findviewbyid(r.id.q7_tv); q8_tv = (textview) findviewbyid(r.id.q8_tv); q9_tv = (textview) findviewbyid(r.id.q9_tv); q10_tv = (textview) findviewbyid(r.id.q10_tv); bt1 = (button) findviewbyid(r.id.bt1); bt2 = (button) findviewbyid(r.id.bt2); bt3 = (button) findviewbyid(r.id.bt3); bt4 = (button) findviewbyid(r.id.bt4); bt5 = (button) findviewbyid(r.id.bt5); bt6 = (button) findviewbyid(r.id.bt6); bt7 = (button) findviewbyid(r.id.bt7); bt8 = (button) findviewbyid(r.id.bt8); bt9 = (button) findviewbyid(r.id.bt9); bt10 = (button) findviewbyid(r.id.bt10); sp = getsharedpreferences("saved_data", mode_private); solved = sp.getint("solved", 0); // loadlevel & resumegame method data class have array strings fill textviews , buttons if (solved > 0) { resumegame(null); } else { loadlevel(null); } }
i assume fetching data in resumegame
& loadgame
methods either web services or local app storage; if try fetching thing in other main thread (ui thread) , data try pass data on ui thread. best way (beginner) use asynctask, usable callbacks in asynctask
be:
doinbackground
: here write code dataonpostexecute
: here can fill ui views button label, text oftextview
i hope in order improve performance.
Comments
Post a Comment