protected override async void OnCreate
        (
            Bundle bundle
        )
        {
            //AndroidCrapApplication.ApplicationLogger.LogDebug("MEMORY 4 : {0}",
            //                                                  GC.GetTotalMemory(false));

            base.OnCreate(bundle);

            SetContentView(Resource.Layout.SplashScreenLayout);

            _progressCount = FindViewById <TextView>(Resource.Id.ProgressCount);

            ImageView splashProgress = FindViewById <ImageView>(Resource.Id.SplashProgress);

            splashProgress.SetBackgroundResource(Resource.Drawable.ProgressSphere);

            AnimationDrawable splashAnimation  = splashProgress.Background as AnimationDrawable;
            Exception         loadingException = null;

            //AndroidCrapApplication.ApplicationLogger.LogDebug("MEMORY 5 : {0}",
            //                                                  GC.GetTotalMemory(false));

            splashAnimation?.Start();
            _loadingContext = this;

            if (_loadingTask == null)
            {
                _loadingTask = CreateLoadingTask
                               (
                    GetString(Resource.String.SplashTextFormat),

                    updateText: (progressText) => UpdateText(progressText),

                    getContext: () => { return(GetContext()); }
                               );
            }

            //AndroidCrapApplication.ApplicationLogger.LogDebug("MEMORY 6 : {0}",
            //                                                  GC.GetTotalMemory(false));

            try
            {
                await _loadingTask;
            }
            catch (Exception exception)
            {
                loadingException = exception;
            }
            finally
            {
                _loadingTask = null;

                splashAnimation?.Stop();
                splashAnimation?.Dispose();
                splashAnimation = null;
                splashProgress  = null;
            }

            /*// http://stackoverflow.com/questions/477572/strange-out-of-memory-issue-while-loading-an-image-to-a-bitmap-object
             *
             * Java.Lang.JavaSystem.RunFinalization();
             * Java.Lang.JavaSystem.Gc();
             * Java.Lang.JavaSystem.RunFinalization();
             * System.Runtime.GCSettings.LargeObjectHeapCompactionMode
             *  = System.Runtime.GCLargeObjectHeapCompactionMode.CompactOnce;
             * GC.Collect();*/

            if (loadingException != null)
            {
                AndroidCrapApplication.ShowExceptionAndExit(this,
                                                            loadingException);
                return;
            }

            //AndroidCrapApplication.ApplicationLogger.LogDebug("MEMORY 7 : {0}",
            //                                                  GC.GetTotalMemory(false));
        }
Example #2
0
        protected override void OnResume()
        {
            bool initializeAdapter = ((BrowseViewState == null) ||
                                      (PortableObjectRepository <Activity> .HasUnreadSourceChanges));

            if (initializeAdapter)
            {
                List <ObjectItem> objectRenderers;

                try
                {
                    objectRenderers
                        = PortableObjectRepository <Activity> .GetEnabledObjects <ObjectItem>()
                          .ToList();
                }
                catch (Exception exception)
                {
                    IsHandlingException = true;

                    base.OnResume();

                    AndroidCrapApplication.ShowExceptionAndExit(this,
                                                                exception);
                    return;
                }

                _objectViewAdapter = new AndroidBrowseObjectsAdapter
                                     (
                    RunOnUiThread,

                    (viewGroup) =>
                {
                    try
                    {
                        return(LayoutInflater.Inflate(ItemLayoutResource,
                                                      viewGroup,
                                                      attachToRoot: false));
                    }
                    catch (Exception exception)
                    {
                        throw exception;
                    }
                },

                    () => { return(BrowseFooterFragment.GetScaleType()); },
                    (scaleType) => BrowseFooterFragment.SetScaleType(scaleType),

                    () => { return(Resources); },

                    LoadingResource,

                    this.EditObject,

                    objectRenderers,

                    getString: (resource) => GetString(resource),

                    onCorrupt: (imageException,
                                imageView) =>
                {
                    this.HandleCorruptObject
                    (
                        imageException,
                        imageView,
                        getCount: () => { return(CorruptMesssageCount); },
                        setCount: (currentMassageCount) => { CorruptMesssageCount = currentMassageCount; }
                    );
                }
                                     );
            }

            base.OnResume();

            AbstractBrowseView.ItemClick -= ObjectItemClicked;
            AbstractBrowseView.ItemClick += ObjectItemClicked;

            bool isDataChanged = false;

            PortableBaseObject pendingObject = PortableObjectRepository <Activity> .PopPendingObject();

            while (pendingObject != null)
            {
                _objectViewAdapter.AddPendingObject(pendingObject);

                isDataChanged = true;

                pendingObject = PortableObjectRepository <Activity> .PopPendingObject();
            }

            if (isDataChanged)
            {
                _objectViewAdapter.NotifyDataSetChanged();
            }
        }