Show a message box on Android


To display a message box on Android you can use AlertDialog class. It has many options, however I'll use the most simple example:

// ...
import android.content.DialogInterface;

public class MessageBox
    void show(String title, String message)
        dialog = new AlertDialog.Builder(activity) // Pass a reference to your main activity here
            .setPositiveButton("OK", new DialogInterface.OnClickListener()
                public void onClick(DialogInterface dialogInterface, int i)

    private AlertDialog dialog;

Note that .show() method doesn't block the caller thread like it does with WinAPI MessageBox or JavaScript alert functions.

Rate this post:
Share this page:

See also how to:

How to call your native functions in Android NDK application from Java
How to use JNIEnv::FindClass on Android and what you should know about it
How to open URL in web browser from Android NDK application with Java or native code
How to get App ID for your mobile application in AdMob platform
How to find all Clang arguments that used to build native code in Android Studio