You can pass the context of this activity to your class by passing a value to the nonActivity class
example:
new NonActivityClass(Activityclass.this) ;
and as in the answer above
new MyClass(ActivityClass.this);
In NonActivityClass
public class NonActivityClass { public NonActivityClass (Context context) { Toast.makeText(context, "mymessage ", Toast.LENGTH_SHORT).show(); } }
Hope this works for you ...
source share