Question

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

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top