Forum Xamarin.Android
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

Toast from Custom class

Hello there,

I have a PCL project that I want to use to share the maximum logic between different devices (WP, Android, IOS, etc.)
I'm currently trying to make Toast messages.

Everything go fine if I do that in my Activity class. But if I want to create a Toast from a "basic" class (implementation of an abstraction class used to share UI Messaging), it just crash. No exception, nothing.

I think that the problem is the Context parameter.
I tried to give :

  • Application.Context
  • Application.Context.ApplicationContext
  • And I manage to pass to this "basic" class the current Activity

Everything failed.

Does someone have some hints to help me ?

Thank you.



  • ashalvaashalva GEMember ✭✭✭


    Can you post the part of the code from where are you calling your basic class and how you are calling the toast?
    If you pass the current Activity in the constructor of the basic class it should not fail.
    Also post the exception messages.

  • AleksandarLUKICAleksandarLUKIC USMember ✭✭

    Thanks Ashalva,

    I found my problem.

    Using a try catch block I get the Exception : "Can't create handler inside thread that has not called Looper.prepare()"
    So I used a Handler to post the Toast and everything is OK now.

    Thank you.

  • ashalvaashalva GEMember ✭✭✭

    You are welcome!

Sign In or Register to comment.