get_post_types not working properly in admin

register_post_type is recommended to be used in init action hook. So, get_post_types should be used in an action after init. Hooking in init with a very high priority, 999 or greater, should also work in almost every situation but it is safer to use a later action hook.

Example:

add_action('wp_loaded', function(){
        $post_types = get_post_types( array( 'public' => true ), 'names' ); 
        var_dump($post_types);
});

In admin section you can use admin_init, which run after init:

add_action('admin_init', function(){
        $post_types = get_post_types( array( 'public' => true ), 'names' ); 
        var_dump($post_types);
});