Android Tutorial: How to create a feedback button

How to create a feedback button

In this tutorial I will show you how to implement a feedback button in your Android application. You can also use this code to compose other emails from within your app.

Creating the layout file

For this tutorial I will use a button to trigger the feedback code, but you can also use a menu option or an item in your preference screen in your final app.

First we will begin by putting a button on a layout called “activity_main.xml”

<RelativeLayout xmlns:android=""
    xmlns:tools="" android:layout_width="match_parent"
    android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">
        android:text="@string/button_feedback" />

As you can see I have created a button called “btn_feedback”, it’s text is specified by a resource string and its OnClick event is set to “btnFeedbackOnClick”.

Adding the string resources

Now we will specify our resource strings, these are allocated in the file “res/values/strings.xml”. Using string resources helps us change the strings later if we want to and it makes it easy to add translations for the strings if we need to.

    <string name="app_name">Feedback example</string>
    <string name="button_feedback">Send feedback</string>        
    <string name="title_send_feedback">Send feedback</string>

    <string name="mail_feedback_email">YourEmailAdress</string>
    <string name="mail_feedback_subject">Feedback on your app</string>
    <string name="mail_feedback_message">Hi, 
\n\nYour Feedback sample app rocks! I would like to give you some feedback:</string>

“app_name”: Your application title.
“button_feedback”: Text on feedback button.
“title_send_feedback”: Title of chooser dialog.
“mail_feedback_email”: Email address where the feedback is going.
“mail_feedback_subject”: Subject of the email.
“mail_feedback_message”: Default mail message.

Coding the feedback button

Now we need to create our activity. I Have named my activity MainActivity and the corresponding class file is named “”. As You can see in the next part of the code I am using the support library in this example. This of course is not necessary, you can also extend from the Activity class if you want to.

package com.example.feedbackexample;

import android.os.Bundle;
import android.view.Menu;

public class MainActivity extends AppCompatActivity {

    protected void onCreate(Bundle savedInstanceState) {

    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(, menu);
        return true;

Next we add an OnClickListener for the button in the OnCreate method.

    protected void onCreate(Bundle savedInstanceState) {
        findViewById( View.OnClickListener() {
            public void onClick(View v) {

Now for the actually feedback message code. I’ve created a private method called sendFeedback which will create an intent that will start an activity to compose the feedback email.

    //Start a new activity for sending a feedback email
    private void sendFeedback() {
        final Intent _Intent = new Intent(android.content.Intent.ACTION_SEND);
        _Intent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{ getString(R.string.mail_feedback_email) });
        _Intent.putExtra(android.content.Intent.EXTRA_SUBJECT, getString(R.string.mail_feedback_subject));
        _Intent.putExtra(android.content.Intent.EXTRA_TEXT, getString(R.string.mail_feedback_message));
        startActivity(Intent.createChooser(_Intent, getString(R.string.title_send_feedback)));

Last thing is to the new sendFeedback method from the button’s OnClickListener, and that’s it.

        findViewById( View.OnClickListener() {
            public void onClick(View v) {

For this example I am using type “text/html” you can also use “text/plain” but when testing I found that this did not work for all email clients.

I hope this post will help you develop your Android app.
Till next post.

Example project

An example project for this article can be found on Github.

More information

For more information see the developer online reference:

2 comments on “Android Tutorial: How to create a feedback button

    • In that case you should be looking at a different solution. For example you could make a webpage that accepts a call from the app with a parameter for a message that the user has typed in the app. On the server site you could then log those messages to a database or save them as files. In that case I suggest that you look at how to make a http request. This webpage might be useful for you:

Leave a Reply

Your email address will not be published. Required fields are marked *