Toasts on Android and "getApplicationContext()" problem

  • Hi,
    in my app I wanna use the Toast function of Android and wanna call it through callStaticMethod. Here is my code:
    @ public static void settoast(String s)
    Toast.makeText(____, s, Toast.LENGTH_SHORT).show();
    There, where u can see ____ has to be the contex but I really dont know how to get it. I also tried this:

    @ private static NotificationClient m_instance;

    public NotificationClient()
        m_instance = this;
    public static void settoast(String s)
        Toast toast = new Toast();
        toast.makeText(m_instance.getApplicationContext(), s, Toast.LENGTH_LONG).show();

    but it didnt work.
    Actually the App crashed instant...
    Could u please tell me what context i have to use in this gap?

    Thx for helping me

  • We are using the application context in our "plugins": with the help of the QtNative java class (bundled within the default Qt classes) with a call to the "activity()": method:

    This method should be globally accessible as it's declared as static & public and gets set by Qt itself.

    Make also sure to call the UI-related Toast method on the UI thread (with runOnUiThread()).

    Hope this helps!

    Alex from V-Play

Log in to reply