Rg.Plugins.Popup icon indicating copy to clipboard operation
Rg.Plugins.Popup copied to clipboard

Initialize Rg inside other activity (splash screen)

Open Cvijo opened this issue 4 years ago • 5 comments

💬 Questions and Help

Hi, In Xamarin I am using splash screen to play some Lottie animation and during animation, I am initializing all libraries (even creating a new App())

So my Splash screen inherits Activity, IAnimatorListener when my Lottie animation start I begin registering all libraries in background thread

part of code in my SplashActivity


    [Activity(Label = "MyApp", Theme = "@style/MyApp.Splash", MainLauncher = true, NoHistory = true)]
    public class SplashActivity : Activity, IAnimatorListener
    {
. 
.
.
        public async void OnAnimationStart(Animator animation)
        {
            if (IsInitializing == false && MainActivity.OPTIMIZE_STARTUP)
            {
                await Task.Run(() => Init(this, savedInstanceState))
                    .ContinueWith(app => IsLoaded = true);
            }
        }

        private App Init(Activity context, Bundle savedInstanceState)
        {
            Forms.Init(context, savedInstanceState);
            Xamarin.Essentials.Platform.Init(context, savedInstanceState);
            FormsMaterial.Init(context, savedInstanceState);
            OneSignal.Current.StartInit(API_KEY)
                 .InFocusDisplaying(OSInFocusDisplayOption.Notification)
                 .EndInit();
            FFImageLoading.Forms.Platform.CachedImageRenderer.Init(enableFastRenderer: true);
            Rg.Plugins.Popup.Popup.Init(context);  //-- this doesn't work if not in main activity
            MainActivity.AppInstance = new App();
            return MainActivity.AppInstance;
        }
 }

everything works fine except this line Rg.Plugins.Popup.Popup.Init(context); if I move it to main activity it's working I am just wondering why .. it's no problem to put it in the main activity it's just a few ms initializations but maybe I am doing something wrong here?

I even try to use Application.Contex instead of this, tried to inherit FormsAppCompatActivity instead of Activity and many other things but only init() in main activity working

Cvijo avatar Nov 06 '21 15:11 Cvijo

Hmm, what error do you get from this? As long as what you pass is of type Android.Content.Context it should be functional

LuckyDucko avatar Nov 12 '21 06:11 LuckyDucko

There is no error, not in debug window or anywhere it just doesn't work. Popup doesn't show, if I put it in my main activity it works. And yes I am passing "this" from splash activity

Cvijo avatar Nov 15 '21 08:11 Cvijo

Huh, could you try and remake what you're doing in a demo project, zip and put it here, and i can go through and poke about?

LuckyDucko avatar Nov 16 '21 03:11 LuckyDucko

Hi, here is a simplified version of the demo, when you init Rg on another thread or on another activity it doesn't work, if you uncomment the first line it works.

I remove most of the things and simplified activity but it reproduces issues with Rg .. navigation stacks are still counting but the popup doesn't show

Rg_demo.zip

Cvijo avatar Dec 01 '21 18:12 Cvijo

I'm facing the same issue. If somebody is using Prism.Plugin.Popups it is required to call Rg.Plugins.Popup.Popup.Init(this); in SplashActivity (before Forms init) and again in MainActivity. Simply moving it from SplashActivity to MainActivity does not solve the problem. Affected version: 2.0.0.14

RonnyBansemer avatar Jan 06 '22 16:01 RonnyBansemer