Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash when targeting Android 11 #16

Open
tranb3r opened this issue Nov 30, 2020 · 17 comments
Open

Crash when targeting Android 11 #16

tranb3r opened this issue Nov 30, 2020 · 17 comments

Comments

@tranb3r
Copy link

tranb3r commented Nov 30, 2020

Toast getView() was deprecated on Android 11 and it returns null.
So when targeting Android 11, the sample app crashes:

**System.NullReferenceException:** 'Object reference not set to an instance of an object.'
  at Plugin.Toast.ShowToastPopUp.ShowMessage (System.String message, System.String backgroundHexColor, System.String textHexColor, Plugin.Toast.Abstractions.ToastLength toastLength) [0x0003d] in C:\Users\10061213\Toast\Toast.Plugin.Android\ShowToastPopUp.cs:79 
  at Plugin.Toast.ShowToastPopUp.ShowToastMessage (System.String message, Plugin.Toast.Abstractions.ToastLength toastLength) [0x00000] in C:\Users\10061213\Toast\Toast.Plugin.Android\ShowToastPopUp.cs:45 
@tranb3r
Copy link
Author

tranb3r commented Nov 30, 2020

@tranb3r
Copy link
Author

tranb3r commented Dec 8, 2020

My suggestion if you do not have the time to work on a full fix, would be to skip colors assignments on android 11, which would avoid the crash.
I can do the PR if you want.

@ishrakland
Copy link
Owner

Hello , @tranb3r i will fix it as soon as possible. Thank you for your help.

@tranb3r
Copy link
Author

tranb3r commented Jan 4, 2021

@ishrakland Any update ? A quick fix to prevent the crash by ignoring colors would be good enough...

@ishrakland
Copy link
Owner

try custom toast you can specify the color you want. I will fix it : i have a lot of charge.

@tranb3r
Copy link
Author

tranb3r commented Jan 5, 2021

The crash occurs whatever color you specify.
Again, a quick workaround to prevent the crash would be to skip color assignments on android 11.
Let me know if you need some help with the PR.

@jpveldtman
Copy link

Experiencing the same issue

@tranb3r
Copy link
Author

tranb3r commented Jan 18, 2021

@ishrakland I understand you may not have the time to work on this issue. Do you think you can provide a fix, or at least merge a quick fix to prevent the crash if I do the PR ?
I really like this plugin, but considering the impact of this issue, I'm thinking about moving to xamarin-community-toolkit which also has a toast functionnality.

@douglassimaodev
Copy link

Same problem here.... and based on the time it got reported.. I assume it won't get fix soon

@ishrakland
Copy link
Owner

ishrakland commented Jul 9, 2021 via email

@sunkerGit
Copy link

GWS @ishrakland :D

@ishrakland
Copy link
Owner

ishrakland commented Jul 29, 2021

It's free plugin, opensource and i don't get money from it . it's open for all users to contribute.

@tranb3r
Copy link
Author

tranb3r commented Jul 29, 2021

Maintaining this kind of plugin is too big a challenge for the long-term, and the xamarin community toolkit already has a toast functionality.
I think you should consider merging your code into their repo if you think you can provide additional features.

@ishrakland
Copy link
Owner

@tranb3r Yes, thank you

@tranb3r
Copy link
Author

tranb3r commented Aug 25, 2021

Did you find any solution @tranb3r

Yes, I'm using xamarin community toolkit now, instead of this plugin.

@iane87
Copy link

iane87 commented Oct 7, 2021

I'm thinking that the following changes in ShowToastPopUp.cs in Android should fix it

private void ShowMessage(string message, string backgroundHexColor = null, string textHexColor = null, Abstractions.ToastLength toastLength = Abstractions.ToastLength.Short)
        {
            var length = toastLength == Abstractions.ToastLength.Short ? Android.Widget.ToastLength.Short :  Android.Widget.ToastLength.Long;
            // To dismiss existing toast, otherwise, the screen will be populated with it if the user do so
            _instance?.Cancel();
            _instance = Android.Widget.Toast.MakeText(Android.App.Application.Context, message, length);
            if (Xamarin.Essentials.DeviceInfo.Version.Major <= 10)
            {
                View tView = _instance.View;
                if (!string.IsNullOrEmpty(backgroundHexColor))
                    tView.Background.SetColorFilter(Color.ParseColor(backgroundHexColor), PorterDuff.Mode.SrcIn);//Gets the actual oval background of the Toast then sets the color filter

                TextView text = (TextView)tView.FindViewById(Android.Resource.Id.Message);
                if (!string.IsNullOrEmpty(textHexColor))
                    text.SetTextColor(Color.ParseColor(textHexColor));
                
            }
            _instance.Show();
        }

@aproko234
Copy link

Hi.

This issue is still repeating in Android 11.

When are you coming out with the updated plugin.toast to handle this issue?

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants