I needed to display alerts in processing android so I got some code from another post and boiled it down to this
import android.app.AlertDialog;
String alertMessage;
void setup() {
alertMessage = "This is the message";
createAlert();
}
void createAlert() {
runOnUiThread(new Runnable() {
@ Override
public void run() {
AlertDialog.Builder alertDialog = new AlertDialog.Builder(getActivity());
alertDialog.setTitle("Alert");
alertDialog.setMessage(alertMessage);
alertDialog.setPositiveButton("OK", null);
alertDialog.show();
}
}
);
}
Which works great but now to display some text in an alert I have to change the alertMessage and then call the function, there must be a way to turn it into a function that takes in a string, something like this createAlert("This is the message");
but I cant figure out how to do it with the UiThread being inside the function.
Any advice?