android - Too many Activity in the stack make the app pretty slow -


recently created social app. didn't use fragment , project finished. have several activities userprofile, followers, followings activity.

normally it's working fine. if user click usera userprofile activity -> , click a's followers -> select userb userprofile activity -> click b's followers activity -> select userc userprofile activity....

in loop, app pretty slower because opened many activities @ same time , stack hold of them.

i wonder if there's optimization situation? because userprofile activity layout same except user information content. possible use fragment each activity, though different activities show in sequence 1 one?

thanks!

you should architect in different way. should ever have 1 userprofileactivity in stack. if have userprofileactivity user in stack, , want show userprofileactivity user b, call startactivity() userprofileactivity intent.flag_activity_reorder_to_front , pass extras indicate activity should show user b. use same concept of activities.

to make sure button navigation works correctly, need override onbackpressed() , figure out activity needs shown , data. call startactivity() , set intent.flag_activity_reorder_to_front , provide extras activity show correct data.

to assist in keeping track of in navigation, might want create stack of items stored in static variable somewhere. each item indicate activity being shown , data. every time launch new activity, push new item on stack, , every time user presses key, pop top item off stack , @ 1 underneath determine activity start , data send in extras.

with scheme, user can click around day long , never have more 1 instance of each activity, user still able navigate way back.


Comments

Popular posts from this blog

sql server - Cannot query correctly (MSSQL - PHP - JSON) -

php - trouble displaying mysqli database results in correct order -

C++ Linked List -