locked
Unable to use Toast, Activity Indicatior RRS feed

  • Question

  • User394429 posted

    I have a simple Xamarin Form app with a .net standard project and Android Project. I am facing a problem since day of development is that , I am unable to pull Toast and Activity Indicator on form. I dont know why. I tried almost all major plugins as well.

    Here's my login code where I want to see a toast. I have used UserDialogs, Forms.Plugin etc and now using Plugin.Toast.

      protected void BtnLogin_Clicked(object sender, EventArgs e)
    
            {
                try
                {
                    CrossToastPopUp.Current.ShowToastMessage("Message"); // Plugin.Toast package
                    var userName = TxtUserName.Text.Trim();
                    var password = TxtPassword.Text.Trim();
                    userController.DoLogin(userName, password);
                }
                catch (NullReferenceException)
                {
                    DisplayAlert("Mobile # and Password, both are required.", "JCAA", "OK");
    
                }
                catch (Exception ex)
                {
                    DisplayAlert(ex.Message, "JCAA", "OK");
                    Crashes.TrackError(ex);
                }
    
    
            }
    
    Friday, May 8, 2020 12:33 PM

All replies

  • User42420 posted

    @amitranjan said: I have a simple Xamarin Form app with a .net standard project and Android Project. I am facing a problem since day of development is that , I am unable to pull Toast and Activity Indicator on form. I dont know why. I tried almost all major plugins as well.

    Here's my login code where I want to see a toast. I have used UserDialogs, Forms.Plugin etc and now using Plugin.Toast.

      protected void BtnLogin_Clicked(object sender, EventArgs e)
    
            {
                try
                {
                    CrossToastPopUp.Current.ShowToastMessage("Message"); // Plugin.Toast package
                    var userName = TxtUserName.Text.Trim();
                    var password = TxtPassword.Text.Trim();
                    userController.DoLogin(userName, password);
                }
                catch (NullReferenceException)
                {
                    DisplayAlert("Mobile # and Password, both are required.", "JCAA", "OK");
    
                }
                catch (Exception ex)
                {
                    DisplayAlert(ex.Message, "JCAA", "OK");
                    Crashes.TrackError(ex);
                }
    
    
            }
    

    Please do not use 3rd party libraries unless really needed. For Simple display alert : Device.BeginInvokeOnMainThread (() => { DisplayAlert("Hello World!!", "OK"); });

    If you are willing to use 3rd party library only for Pop-Ups then please use Rg-Plugin Pop Up.

    Mark as answer if it resolves your issue!

    Friday, May 8, 2020 2:09 PM
  • User42420 posted

    Why are you using Display Alert at one part and 3rd party for another?? Is it good way?

    Use Rg-Plugin Pop Up if you are interested to use 3rd party ready made libraries only!

    Friday, May 8, 2020 2:11 PM
  • User394429 posted

    I am beginner in Xamarin forms. Me to advocate native stuffs only, like Toast, DisplayAlert and Activity indicator. But unfortunately Toast and ActivityIndicator is not working. I am not able to see these two. That's why i have to opt for third party tools. Earlier I was using UserDialogs for display alert and all..

    Please help me achieving the same. Also please not, My methods are synchronous, not asynchronous. So please give me answer in this context.

    Friday, May 8, 2020 4:16 PM
  • User394496 posted

    if you want write a good xamarin app,you must learn Andorid and ios......i write a library that you can popup or toast a contentview

    Saturday, May 9, 2020 7:37 AM
  • User394429 posted

    @liwuyang Let me know what should i know about android and ios in order to develop better apps. Please share some links or references for the areas where i need to look more. Dont share links like What is Android etc

    Saturday, May 9, 2020 10:03 AM
  • User369978 posted
    1. To use Toast functionality , we don't need to use third-party plugin , it can be implement easily to use dependency service , detail refer here . Actually , Plugin.Toast is taking this way ,check its source code .

    2. Plugin.Toast works perfect on my side , are you using the latest plugin ? Is it 2.1.2 ? Do you also try to install the plugin into Android project ? Can you create a blank project to check if problem persists ?

    3. About iOS and Android , it's enough to learn them from the official documentation .

      Android : https://docs.microsoft.com/en-us/xamarin/android/ .

      iOS : https://docs.microsoft.com/en-us/xamarin/ios/.

    Monday, May 11, 2020 6:00 AM
  • User369978 posted

    Hi , is there any update ?

    Friday, May 15, 2020 7:44 AM
  • User394496 posted

    @ColeX said: Hi , is there any update ?

    in fact,we can use xamarin form's contentview replace default toast view in android or ios.xamarin official team should help us,it is not difficulty for them B) !

    Saturday, May 16, 2020 2:05 AM
  • User390979 posted

    @ColeX said: 1. To use Toast functionality , we don't need to use third-party plugin , it can be implement easily to use dependency service , detail refer here . Actually , Plugin.Toast is taking this way ,check its source code .

    1. Plugin.Toast works perfect on my side , are you using the latest plugin ? Is it 2.1.2 ? Do you also try to install the plugin into Android project ? Can you create a blank project to check if problem persists ?

    2. About iOS and Android , it's enough to learn them from the official documentation .

      Android : https://docs.microsoft.com/en-us/xamarin/android/ .

      iOS : https://docs.microsoft.com/en-us/xamarin/ios/.

    This is an odd reply.

    You are advocating missing functionality like being a feature as you can write them yourself. Of course anything can be written from scratch, but it is not productive if everyone were to write basic functionality from scratch for every single platform. Of course a plug-in should be used whenever possible.

    And the Xamarin team’s view on how much native development must be known is "it’s enough to learn them from the official documentation". Really now, you sure that’s enough? I’m no longer sure I understand how Xamarin is positioned.

    Thanks.

    Saturday, May 16, 2020 6:39 AM
  • User394429 posted

    @ColeX said: Hi , is there any update ?

    Hi ColeX, I managed to get it using Dependency, see the implementation below:

    [assembly: Xamarin.Forms.Dependency(typeof(ToastDroid))]
    namespace JCAA.Droid
    {
        class ToastDroid : IToast
        {
            public void Show(string message)
            {
                 Toast.MakeText(Application.Context, message, ToastLength.Long).Show();
            }
        }
    }
    

    But the problem is that (see the code below as example) , instead of displaying toast immediately after clicking , it shows up in the next page , i.e. Dashboard.

    protected void BtnLogin_Clicked(object sender, EventArgs e)
      {
                try
                {
                     DependencyService.Get<IToast>().Show("Please wait....");
                    var userName = TxtUserName.Text.Trim();
                    var password = TxtPassword.Text.Trim();
                    userController.DoLogin(userName, password);
                    Application.Current.MainPage =new NavigatioPage( new Dashboard()); ///toast displays on this page, post rendering
                }
                catch (NullReferenceException)
                {
                    DisplayAlert("Mobile # and Password, both are required.", "JCAA", "OK");
                }
                catch (Exception ex)
                {
                    DisplayAlert(ex.Message, "JCAA", "OK");
                    Crashes.TrackError(ex);
                }
    
            }
    
    Friday, May 22, 2020 12:48 PM
  • User369978 posted

    @amitranjan said:

    @ColeX said: Hi , is there any update ?

    Hi ColeX, I managed to get it using Dependency, see the implementation below:

    [assembly: Xamarin.Forms.Dependency(typeof(ToastDroid))]
    namespace JCAA.Droid
    {
        class ToastDroid : IToast
        {
            public void Show(string message)
            {
                 Toast.MakeText(Application.Context, message, ToastLength.Long).Show();
            }
        }
    }
    

    But the problem is that (see the code below as example) , instead of displaying toast immediately after clicking , it shows up in the next page , i.e. Dashboard.

    protected void BtnLogin_Clicked(object sender, EventArgs e)
      {
                try
                {
                     DependencyService.Get<IToast>().Show("Please wait....");
                    var userName = TxtUserName.Text.Trim();
                    var password = TxtPassword.Text.Trim();
                    userController.DoLogin(userName, password);
                    Application.Current.MainPage =new NavigatioPage( new Dashboard()); ///toast displays on this page, post rendering
                }
                catch (NullReferenceException)
                {
                    DisplayAlert("Mobile # and Password, both are required.", "JCAA", "OK");
                }
                catch (Exception ex)
                {
                    DisplayAlert(ex.Message, "JCAA", "OK");
                    Crashes.TrackError(ex);
                }
    
            }
    

    Please mark your solution and the answer which helped you .

    Monday, May 25, 2020 1:40 AM
  • User390979 posted

    @ColeX said:

    @amitranjan said:

    @ColeX said: Hi , is there any update ?

    Hi ColeX, I managed to get it using Dependency, see the implementation below:

    [assembly: Xamarin.Forms.Dependency(typeof(ToastDroid))]
    namespace JCAA.Droid
    {
        class ToastDroid : IToast
        {
            public void Show(string message)
            {
                 Toast.MakeText(Application.Context, message, ToastLength.Long).Show();
            }
        }
    }
    

    But the problem is that (see the code below as example) , instead of displaying toast immediately after clicking , it shows up in the next page , i.e. Dashboard.

    protected void BtnLogin_Clicked(object sender, EventArgs e)
      {
                try
                {
                     DependencyService.Get<IToast>().Show("Please wait....");
                    var userName = TxtUserName.Text.Trim();
                    var password = TxtPassword.Text.Trim();
                    userController.DoLogin(userName, password);
                    Application.Current.MainPage =new NavigatioPage( new Dashboard()); ///toast displays on this page, post rendering
                }
                catch (NullReferenceException)
                {
                    DisplayAlert("Mobile # and Password, both are required.", "JCAA", "OK");
                }
                catch (Exception ex)
                {
                    DisplayAlert(ex.Message, "JCAA", "OK");
                    Crashes.TrackError(ex);
                }
    
            }
    

    Please mark your solution and the answer which helped you .

    He's saying it doesn't work.

    Monday, May 25, 2020 2:48 PM