Xamarin form app restarts when theme is changed.

Raj 1 Reputation point
2021-12-17T07:05:56.23+00:00

Steps:

  1. Xamarin form app is installed on Android.
  2. Change the theme in Settings app.
  3. From multitask go back to the form app
  4. The app will restarts.

Expected : The dark theme should be applied without the app restart.

Please let us know if any other workarounds.

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,261 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. JarvanZhang 23,931 Reputation points
    2021-12-20T06:18:18.327+00:00

    Hello,​

    Welcome to our Microsoft Q&A platform!

    The dark theme should be applied without the app restart.

    To respond to theme changes on Android, please make sure you've included the ConfigChanges.UiMode flag in the Activity attribute of your MainActivity class as below.

       [Activity(Theme = "@style/MainTheme", MainLauncher = true, ConfigurationChanges = =ConfigChanges.UiMode ...)]  
       public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity  
       {  
           ...  
       }  
    

    For more details, you could refer to this doc: https://developer.android.com/guide/topics/resources/runtime-changes

    Best Regards,

    Jarvan Zhang


    If the response is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    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.

    0 comments No comments