I want to create a global shortToast and longToast method to use it dynamically in all other activities I have, so I don't have to define the Toast method in every activity.
I've tried this, but Android Studio tells me that this is a memory leak:
public static Activity thisActivity = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
thisActivity = this;
}
public static void shortToast()
{
Toast.makeText(thisActivity, "message" , Toast.LENGTH_SHORT).show();
}
public static void longToast()
{
Toast.makeText(thisActivity, "message" , Toast.LENGTH_LONG).show();
}
What can I do instead to achieve this goal having a global toast method (without memory leak)?