Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android back button does not restart activity?

My app intiates an activity. On the click of a button, the app opens up the browser with a webpage. When I hit the back button, it comes back to my initial activity screen, but does not resume or restart the activity.

When I put all the layout code and activity code in onResume instead of onCreate, the activity gets restarted.

My question is whether this is the right way to go about it? Can I use onResume to draw my layout and initiate the activity, or is this poor design? When the browser fires up, does the initial activity forget its layout?

Please let me know what you suggest.

Thanks Chris

like image 520
Chris Avatar asked Nov 15 '22 10:11

Chris


1 Answers

Mostly you should read about the Activity Life Cycle.

It is fine to initialize in onResume as long as you only do it once. Either have a dedicated hasInitialized member or check some other value that will have equivalent meaning, and do not initialize again if it is set.

like image 166
drawnonward Avatar answered Dec 28 '22 08:12

drawnonward