Hello,
Welcome to our Microsoft Q&A platform!
I am simply unsure whether to put my code in OnCreate or OnResume, since in many (although not all) cases they are both called.
OnResume event will be called every time the Activity comes to the foreground. OnCreate ** fires when the system creates the activity. When the screen is rotated, the Activity will be recreated and some lifecycle methods such as **OnCreate and OnResume will be called again. Check the doc.
If you don't want to recrate the Activity, you can declare that your activity handles the configuration change itself which prevents the system from restarting your activity. Set the ConfigurationChanges = ConfigChanges.Orientation | ConfigChanges.KeyboardHidden | ConfigChanges.ScreenSize
configuration for the Activity as below.
[Activity(Label = "@string/app_name", Theme = "@style/AppTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.Orientation | ConfigChanges.KeyboardHidden | ConfigChanges.ScreenSize)]
public class MainActivity : AppCompatActivity
{
...
}
Related doc: https://developer.android.com/guide/topics/resources/runtime-changes#HandlingTheChange
Best Regards,
Jarvan Zhang
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.