androidandroid-layoutandroid-menumenu-items

Different menu items for Activity in debug and release mode


For the application that I am developing, there are some menu items that are helpful for debugging the app (something like resetting counts and stuff).

Is there a way (a directive in xml file or else) to tell android to show/hide certain menu items depending on the app being in debug mode or not?

The only thing I know is the following code, that we can do in the Activity itself, I wonder if it can be used to show/hide menu items:

boolean isDebugBuild = (0 != ( //Check if the app is in debug mode
        getApplicationInfo().flags & ApplicationInfo.FLAG_DEBUGGABLE));

Or maybe is there a way to do this in onCreateOptionsMenu()


Solution

  • Add this in your AndroidManifest application tag

    android:debuggable=true
    

    and in onCreateOptionsMenu check

     if (BuildConfig.DEBUG) {
            //true for debuggable mode
        } else {
        }