Itβs good to be prepared for everything when you start activity in another application (Camera). Activity can return bad data, the screen orientation can be changed, or it can be very long before the user returns to your application. From your description, it sounds as if the orientation changes each time you start the Camera application.
Android has built-in state management methods for working with this type of script. You can override the onSaveInstanceState() method to save the activity state (for example, counter values), and then restore this state to onCreate() . (An example is here .) This will handle the case when you launch the Camera application, or the user clicks the Home button, and then returns to the application, etc.
EDIT
onRestoreInstanceState() is called only if your activity is killed due to memory pressure and then recreated later. It is much more reliable to use the Bundle passed to onCreate() (which is called again after the device rotates). This Bundle will contain everything that has been stored in onSaveInstanceState() .
If you need to defer your work to onResume() , you will want to use onCreate() to populate some member variables in your Activity class, and then use these variables in onResume() .
source share