How to Show Admin Notice on Plugin Activation?

1. Add the code in the Notice Class like Below –

	/**
	 * Set transient only when the plugin is activated.
	 *
	 * @since 3.0.2
	 * @return void
	 */
	public static function add_the_transient() {
	    /* Create transient data */
	    set_transient( 'prefix-activation-notice', true, 5 );

	}
	/**
	 * Admin Notice on Activation.
	 *
	 * @since 3.0.2
	 * @return void
	 */
	public function add_activation_notice() {
		$itesm = get_posts( array( 'post_type' => 'my_post_type' ) );
		if ( count( $items ) > 0 ) {
			/* Check transient, if available display notice */
			if ( get_transient( 'prefix-activation-notice' ) ) {
				?>
				<div class="updated notice is-dismissible">
				<p>Thank you for using this plugin! <strong>You are awesome</strong>.</p>
				</div>
				<?php
				/* Delete transient, only display this notice once. */
				delete_transient( 'prefix-activation-notice' );
			}
		}
	}

2. Include the Notice class file in the Main class of the plugin and register the admin hook in the define_admin_hooks method –

// Admin Notice.
$admin_notice = new My_Plugin_Name_Notice( $this->get_plugin_name(), $this->get_version() );
$this->loader->add_action( 'admin_notices', $admin_notice, 'add_activation_notice' );

3. Add the code in the Main plugin file to register activation hook –

/**
 * The code that runs during plugin activation.
 * This action is documented in includes/class-my-plugin-activator.php
 */
function activate_my_plugin_name() {
	My_Plugin_Name_Notice::add_the_transient();
}
register_activation_hook( __FILE__, 'activate_my_plugin_name' );