xamarin android application

hi

i have a xamarin application where in an activity and upon a click i am running a background service to load data into mobile application  where inside the service toast are shown
now when data is downloaded in the service
i need to hide the toast.
is there anyway to do it?
LVL 1
pamela rizkDeveloperAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

David Johnson, CD, MVPOwnerCommented:
only the service can hide the toast since it resides outside of your application
pamela rizkDeveloperAuthor Commented:
ok how ?
David Johnson, CD, MVPOwnerCommented:
where in your service do you have the toast.show?
Build an E-Commerce Site with Angular 5

Learn how to build an E-Commerce site with Angular 5, a JavaScript framework used by developers to build web, desktop, and mobile applications.

pamela rizkDeveloperAuthor Commented:
dear All

here are some details that might help you solving my problem:
private async Task PullAllDataFunction(Message msg, Context _Context)
            {
                
               ShowMessage(_Context, _Context.GetString(Resource.String.downloading_Items));
                await PullData.GetInstance().FetchITemsDataAsync();
				ShowMessage(_Context, _Context.GetString(Resource.String.Customers));
                await PullData.GetInstance().FetchCustomersDataAsync();
              CompletedSelfResult(_Context, msg.Arg1); //here a message that downloading data has been completed
            }

			show message function:
			 private void ShowMessage(Context _Context, string m_Message)
            {
              var m_thread = new Java.Lang.Thread(() =>
                     {
                         Task.Run(() =>
                         {
                             try
                             {
                                 Toast.MakeText(outerInstance, m_Message, ToastLength.Long).Show();
                             }
                             catch
                             {
                                 ToastUtils.ShowMessage(_Context, m_Message);
                             }
                         }).ConfigureAwait(false);//ConfigureAwait is used to avoid deadlocks
                     });
                m_thread.Start();
                
                //

            }

			   public class ToastUtils
        {
            static Toast toast = null;

            public static void ShowMessage(Context context, System.String m_Message)
            {
                try
                {
                    DisplayMessage(context, m_Message);
                }
                catch (System.Exception ex)
                {
                    Log.Debug(TAG, ex.ToString());
                }
            }
            public static void DisplayMessage(Context context, System.String m_Message)
            {
                try
                {
                    if (toast != null)
                    {
                        toast.SetText(m_Message);
                    }
                    else
                    {
                        Toast.MakeText(context, m_Message, ToastLength.Long).Show();
                    }
                    toast.Show();
                    
                }
                catch
                {
                    Looper.Prepare();//checks if there is no Looper already attached to our Thread (remember, only one Looper per Thread) and then creating and attaching a Looper.
                    Toast.MakeText(context, m_Message, ToastLength.Long).Show();
                    Looper.Loop();//cause our Looper to start looping.
                   

                }
            }
        }

Open in new window


i realize that data is completed but message of show customers is showing before message of items
that is why i need when data is downloaded to hide all toast in teh service how can i do that ?

Please advice.
pamela rizkDeveloperAuthor Commented:
this issue has been fixed as below:
     public class ToastUtils
        {
            static Toast toast = null;
            public static void ShowMessage(Context context, System.String m_Message)
            {


                try
                {
                    DisplayMessage(context, m_Message);
                    ClearMessage(context, m_Message);
                }
                catch (System.Exception ex)
                {
                    Log.Debug(TAG, ex.ToString());
                }
            }
            public static void ClearMessage(Context context, System.String m_Message)
            {
                toast.SetText(m_Message);
                toast.Cancel();
            }
            public static void DisplayMessage(Context context, System.String m_Message)
            {

                try
                {
                    toast = Toast.MakeText(context, m_Message, ToastLength.Long);
                    toast.Show();

                }
                catch
                {
                    Looper.Prepare();//checks if there is no Looper already attached to our Thread (remember, only one Looper per Thread) and then creating and attaching a Looper.
                    toast = Toast.MakeText(context, m_Message, ToastLength.Long);
                    toast.Show();
                    Looper.Loop();//cause our Looper to start looping.
                }

            }
        }

Open in new window


i am calling showmessage method that display a message then hide it
so in my case if i need to show a toast loading customer , loading items
loading customer will be shown then it will be hide and load items will be shown ..

thank you
pamela rizkDeveloperAuthor Commented:
thank you

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Mobile

From novice to tech pro — start learning today.