locked
Getting Null value while cast Context as Activity in XF 4.4 version RRS feed

  • Question

  • User390575 posted

    Hi All,

    I am getting null value when cast Context as Activity in Xamarin Forms 4.4 version but this doesn't occur in 4.3 version in Xamarin.Forms.Android platform. So any ideas?

    Thanks in advance !

    Wednesday, November 20, 2019 9:35 AM

Answers

  • User53115 posted

    Where specifically are you trying to cast the Context to an Activity? I know that the Material renderers use a ContextWrapper to apply the material theme, and I think the designer uses a wrapper as well.

    Regardless, there is an extension method available for getting an Activity from a Context: Xamarin.Forms.Platform.Android.ContextExtensions.GetActivity(this Context context)

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Wednesday, November 20, 2019 4:40 PM

All replies

  • User76049 posted

    4.4 is beta, raise the issue on the Xamarin Forms github page and make the team aware of the issue, it will get no visibility here as the team don't monitor these pages https://github.com/xamarin/Xamarin.Forms/issues

    Wednesday, November 20, 2019 10:05 AM
  • User53115 posted

    Where specifically are you trying to cast the Context to an Activity? I know that the Material renderers use a ContextWrapper to apply the material theme, and I think the designer uses a wrapper as well.

    Regardless, there is an extension method available for getting an Activity from a Context: Xamarin.Forms.Platform.Android.ContextExtensions.GetActivity(this Context context)

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Wednesday, November 20, 2019 4:40 PM
  • User390575 posted

    @JoeManke thanks for your solution that works for me :)

    Wednesday, November 20, 2019 6:30 PM
  • User390575 posted

    @NMackay Thanks for your suggestion! :)

    Wednesday, November 20, 2019 6:32 PM