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
MathiasH -
We are using the application context in our "plugins":http://plugins.v-play.net with the help of the QtNative java class (bundled within the default Qt classes) with a call to the "activity()":https://qt.gitorious.org/qt/qtbase/source/439a6fec84a62b9d166b84dc7574ddc250a38bfb:src/android/jar/src/org/qtproject/qt5/android/QtNative.java#L91 method:
@org.qtproject.qt5.android.QtNative.activity()@
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!
Best,
Alex from V-Play