I have several classes in my application. Some of these are classes, services, and pure Java classes. I know that I can display a Toast message from within an Activity, but I would like to show Toast from a pure java class.
In the java class, I pass the context to the constructor, but that doesn't look like a toast.
I created a method in the Application class that takes a string as an argument, hoping that I can generate Toast using the application context, without joy.
How can I create a Toast from a class that is not a service or Activity, etc.
public class LoginValidate{ public LoginValidate(Context context) { this.context = context; nfcscannerapplication = (NfcScannerApplication) context .getApplicationContext(); } public void someMethod(){ nfcscannerapplication.showToastMessage(result); } }
.
///, then in my application class
public void showToastMessage(String message){ Toast.makeText(this.getApplictionContext(), "Encountered a problem with sending tag: " + message, Toast.LENGTH_LONG).show(); }
android android-context toast
turtleboy
source share