Closed dimonovdd closed 3 years ago
@pictos @ahoefling I'm thinking of another way:
public static partial class Platform
{
static Func<Activity> getCurrentActivity;
public static void Init(Func<Activity> getCurrentActivity, Bundle bundle)
=> getCurrentActivity = getCurrentActivity;
internal static Activity AppActivity
=> getCurrentActivity?.Invoke()
?? throw ExceptionHelper.ActivityNotDetected;
}
@pictos @ahoefling I'm thinking of another way:
public static partial class Platform { static Func<Activity> getCurrentActivity; public static void Init(Func<Activity> getCurrentActivity, Bundle bundle) => getCurrentActivity = getCurrentActivity; internal static Activity AppActivity => getCurrentActivity?.Invoke() ?? throw ExceptionHelper.ActivityNotDetected; }
Not sure if you need to go with a fancy Func for that... In Forms apps, the Activity will be always the same
Also, you have a XE dependency, so you don't need to capture the Activity in your Platform class
@pictos This issue is mainly related to xamarin.Android apps
@dimonovdd
@pictos This issue is mainly related to xamarin.Android apps
I see, in that case, I believe that you can use the XE to grab the current activity since that implements all Activity's lifecycle
I don't quite understand what you mean
@dimonovdd your lib has a reference to Xamarin.Essentials. So instead of collecting the activity let the XE handle that for you... I did this on your code and worked.
// on your lib
public static void Init(Activity activity, Bundle bundle) { }
internal static Activity AppActivity => Xamarin.Essentials.Platform.CurrentActivity;
// Sample
base.OnCreate(savedInstanceState);
//NativeMedia.Platform.Init(this, savedInstanceState);
Xamarin.Essentials.Platform.Init(this, savedInstanceState);
global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
@pictos Thank you very much. I completely forgot about the existence of Xamarin.Essentials.Platform.CurrentActivity property.
Description
Added methods overloading for Xamarin.Android with
activity
parameterRelated to issue
API Changes
Added:
PR Checklist
main