Implementing Rate Us Feature In Android

In this tutorial, you will learn how to implement a Rate Us feature in your Android application. Using this feature allows you to prompt a user to rate your Android application. Ratings are determined by Google Play users. Your application’s rating is one of the most important factors influencing its ranking in the various lists and search results in Google Play. It’s also one of the key signals that the editorial staff looks for when curating apps and games for promotion in the store. We will create an activity, and after the application launches twice the user will be prompted to rate the application. So lets begin…

Create a new project in Eclipse File > New > Android Application Project. Fill in the details and name your project RateUsTutorial.

Application Name : RateUsTutorial

Project Name : RateUsTutorial

Package Name : com.androidbegin.rateustutorial

Then name your activity 

Open your and paste the following code.

package com.androidbegin.rateustutorial;

import android.os.Bundle;

public class MainActivity extends Activity {

	public void onCreate(Bundle savedInstanceState) {
		// Set the view from activity_main.xml
		// Launch class

		// Your Codes...



In this activity, we have inserted a function to call class below the setContentView.

Next, create a new class Go to File > New > Class and name it Select your package named com.androidbegin.rateustutorial and click Finish.

Open your and paste the following code.

package com.androidbegin.rateustutorial;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

public class RateUs {
	// Insert your Application Title
	private final static String TITLE = "RateUs Tutorial";

	// Insert your Application Package Name
	private final static String PACKAGE_NAME = "com.androidbegin.rateustutorial";

	// Day until the Rate Us Dialog Prompt(Default 2 Days)
	private final static int DAYS_UNTIL_PROMPT = 0;

	// App launches until Rate Us Dialog Prompt(Default 5 Launches)
	private final static int LAUNCHES_UNTIL_PROMPT = 2;

	public static void app_launched(Context mContext) {
		SharedPreferences prefs = mContext.getSharedPreferences("rateus", 0);
		if (prefs.getBoolean("dontshowagain", false)) {

		SharedPreferences.Editor editor = prefs.edit();

		// Increment launch counter
		long launch_count = prefs.getLong("launch_count", 0) + 1;
		editor.putLong("launch_count", launch_count);

		// Get date of first launch
		Long date_firstLaunch = prefs.getLong("date_firstlaunch", 0);
		if (date_firstLaunch == 0) {
			date_firstLaunch = System.currentTimeMillis();
			editor.putLong("date_firstlaunch", date_firstLaunch);

		// Wait at least n days before opening
		if (launch_count >= LAUNCHES_UNTIL_PROMPT) {
			if (System.currentTimeMillis() >= date_firstLaunch
					+ (DAYS_UNTIL_PROMPT * 24 * 60 * 60 * 1000)) {
				showRateDialog(mContext, editor);


	public static void showRateDialog(final Context mContext,
			final SharedPreferences.Editor editor) {
		final Dialog dialog = new Dialog(mContext);
		// Set Dialog Title
		dialog.setTitle("Rate " + TITLE);

		LinearLayout ll = new LinearLayout(mContext);

		TextView tv = new TextView(mContext);
		tv.setText("If you like " + TITLE
				+ ", please give us some stars and comment");
		tv.setPadding(4, 0, 4, 10);

		// First Button
		Button b1 = new Button(mContext);
		b1.setText("Rate " + TITLE);
		b1.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				mContext.startActivity(new Intent(Intent.ACTION_VIEW, Uri
						.parse("market://details?id=" + PACKAGE_NAME)));

		// Second Button
		Button b2 = new Button(mContext);
		b2.setText("Remind me later");
		b2.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {

		// Third Button
		Button b3 = new Button(mContext);
		b3.setText("Stop Bugging me");
		b3.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				if (editor != null) {
					editor.putBoolean("dontshowagain", true);


		// Show Dialog;

This class allows you to set the preferred launch date and times before the rating the application. When the rate us launches, it shows 3 buttons and at the first button click will open a Google Play Store, and on the second button click will remind the user to rate later and the third button click will close the rate us dialog.

Next, create an XML file for your main graphical layout. Go to res > layout > Right Click on layout > New > Android XML File
Name your new XML file activity_main.xml 

Open your activity_main.xml and paste the following code.


<RelativeLayout xmlns:android=""
    android:layout_height="match_parent" >



Change your application name and texts in your strings.xml and paste the following code. Go to res > values > strings.xml



    <string name="app_name">RateUs Tutorial</string>
    <string name="rateus"> RateUs Tutorial</string>
    <string name="menu_settings">Settings</string>


Finally, run the application twice for the RateUs Dialog to show up. It depends how many launches you have set in your codes. We have set two on application launches until RateUs dialog prompt. You can do modifications by changing the codes below in your class.

 // Day until the Rate Us Dialog Prompt Default(2 Days)
    private final static int DAYS_UNTIL_PROMPT = 0;

    // App launches until Rate Us Dialog Prompt Default(5 Launches)
    private final static int LAUNCHES_UNTIL_PROMPT = 2;


RateUs Tutorial ScreenShot

Source Code 

[purchase_link id=”7858″ text=”Purchase to Download Source Code” style=”button” color=”green”]

Latest comments

this is very useful man.. tankyu very much...but there is one problem every tim eit ask for rating rather i already rates the app... help me about this


Implementing Rate Us Feature In Android



Implementing Rate Us Feature In Android