Is it possible to call a method of Activity
from the regular Java class?
This is the method in the activity:
public void showMessage(String mensaje) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Are you sure you want to exit?")
.setCancelable(false)
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
})
.setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
AlertDialog alert = builder.create();
alert.show();
This is the method of the code in the external (simple java) class:
public void write(String importanChange) {
Context context = //Here I dont know what to do here (It's my question,
//but I tried other aproaches but all failed
((MyActivity)mContext).showMessage(message);
The reason is that I have a framework that detects changes on a simulation (Android Aplication) and later this simulation notifies to this framework changes and it decides whether the change is important or not.
So if the change is important the framework must execute the showMessage method in the activity.