User42590
User42590

Reputation: 2521

OnCreate Calls After OnPause in Android

I am developing an app in which i have create three activities

Here is the process in which these Activties called:

Due to calling of OnCreate again and again my activity not performing tasks correctly.

Please anyone who can help??

Upvotes: 1

Views: 1951

Answers (2)

User42590
User42590

Reputation: 2521

when orientation changes again Oncreate is called. That is why your activity is not running correctly after the first time.

To fix this you have declare this in your Manifest file where the activity is declared:

android:configChanges="keyboardHidden|orientation" 

For android 3.0 and above

android:configChanges="orientation|screenSize|keyboardHidden"

When the app is in landscape and the phone is locked, then the app reorients to portrait and hence onCreate gets called again. To prevent this add the above line.

Upvotes: 2

Steve Pomeroy
Steve Pomeroy

Reputation: 10129

You should never rely on your task stack maintaining all the state you need. Instead, save your activity's state using onSaveInstanceState() and have each activity base its actions on this state or the intent passed to it. By designing your activity flow this way, the activities can be created / destroyed by the system at its will (usually based on memory needs) and your activities will be able to pick up where they left off.

Upvotes: 1

Related Questions