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

416 Views Asked by At

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.

2

There are 2 best solutions below

0
David Wasser On BEST ANSWER

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.

1
Guangyu Bai - MSFT On

According to the Activity's lifecycle. The system calls OnResume when the Activity is ready to start interacting with the user.

When the activity enters the Resumed state, it comes to the foreground, and then the system invokes the callback. This is the state in which the app interacts with the user. The app stays in this state until something happens to take focus away from the app. Such an event might be, for instance, receiving a phone call, the user’s navigating to another activity, or the device screen’s turning off.

So when the device is rotating, this will not call the OnResume() method.

You can refer to the Microsoft document Activity Lifecycle.