Search code examples
c#android-activityxamarin.androidonresumeactivity-lifecycle

Xamarin Android - Is OnResume() method work differently on multiple devices


My question about the OnResume() method which is part of the Activity's lifecycle.

I know that after the OnStart() method the OnResume() will be called and also if the application goes in background and then comes on front again OnResume() will be executed, but is there any case that some OS system might call this method when the device is rotating or something like that or maybe when they put the device on sleep and then open it again?

I've tested it on some devices to rotate the screen while the application is running and it looks like the OnResume() is not executing but obviously I can't test all the devices out there.


Solution

  • If the Activity does not declare that it wants to handle configuration changes by itself (for example, setting android:configChanges="orientation|screenSize|screenLayout|keyboardHidden" in the manifest), then a device orientation change will cause the following:

    • onPause() is called
    • onStop() is called
    • onDestroy() is called (the Activity instance is now dead)
    • a new instance of the Activity is instantiated
    • onCreate() is called on the new instance
    • onStart() is called on the new instance
    • onResume() is called on the new instance

    Also, some devices will cause the Activity to go through the onPause(), onResume() cycle when the lock screen is shown/unlocked. There are also some devices go through the orientation change cycle when the lock screen is shown/unlocked, even though the device orientation is not changed.