1

I'd like to add an activity to my app asking users to rate it, but I'd rather have it only launch when they are exiting out of the app using the back button (so that it doesn't interfere with usefulness). I have a few apps that if I exit out by repeatedly hitting the back button, I get a toast that says 'Tap back to exit ______' so I'm pretty sure that this is possible.

Thomas Hodges
  • 105
  • 1
  • 10
  • So when the your app exits you want this popup message to show or what? – Andrei T Sep 14 '15 at 21:20
  • possible duplicate of [Android - How To Override the "Back" button so it doesn't Finish() my Activity?](http://stackoverflow.com/questions/3141996/android-how-to-override-the-back-button-so-it-doesnt-finish-my-activity) – Kane O'Riley Sep 14 '15 at 21:23
  • This has been asked before, you need to override `onBackPressed` – Kane O'Riley Sep 14 '15 at 21:24
  • Won't that go off everytime someone presses the back button? – Thomas Hodges Sep 14 '15 at 21:49
  • I want a dialog to pop up asking the user how they like the app on a scale of 5 stars, If they rate 3 or below they are invited to email me with comments or complaints, and if they rate 4 or 5 they are sent to the app store to submit a rating. – Thomas Hodges Sep 14 '15 at 21:51

3 Answers3

1

You can start another activity using intent on your onBackPressed method. With this approach you can fire an intent to google play. But i think it would be frustrating for user. In my opinion better way of achieving what you want is using some kind of popup. This library might help you out.

DreadfulWeather
  • 716
  • 3
  • 13
  • Thank you for the tip on the library, it looks like that might help a lot. I also don't want the thing popping up every time the user presses the back button because my app requires regular use of the back button. – Thomas Hodges Sep 14 '15 at 21:42
  • I ended up using this library. It's not *exactly* my goal but it will do for now until I become a more advanced programmer. – Thomas Hodges Sep 15 '15 at 00:32
1

As far as I see I would do it like in the following code(not tested, just a snippet):

boolean exitApp = false;

@Override
public void onBackPressed() {
    if (exitApp && (isBackStackEntryEmpty())) {
        super.onBackPressed();
        return;
    }
    //put here a dialog check
    checkDialog();  
}

private void checkDialog(){
  //show a dialog with an ok or a cancel.
  //in the cancel it will ask you for a second press.
  //if ok is pressed go to rate else, cancel, see below.
  this.exitApp = true;
  showToast();
  postDelayed();
}

private Handler handler = new Handler();
private boolean isBackStackEntryEmpty(){
   return isBackStackEntryEmpty;// check for that in code.
}

private void postDelayed()
{
   handler.postDelayed(new Runnable()
   {
      @Override
      public void run() {
           this.exitApp = false;                      
      }
   }, 3000);
}

public void showToast(){
   Toast.makeText(this, "Please click again to exit", Toast.LENGTH_SHORT).show();
}


Similar:
Clicking the back button twice to exit an activity

Community
  • 1
  • 1
Andrei T
  • 2,985
  • 3
  • 21
  • 28
  • Thank you, that looks perfect! – Thomas Hodges Sep 14 '15 at 21:54
  • actually it's getting caught if I have a fragment on screen besides my level 1 fragment. For the code to check the backstack I had it return (fm.getBackStackEntryCount() == 0); (where fm is my FragmentManager). Could that be the problem? – Thomas Hodges Sep 14 '15 at 22:13
0

Just a thought...record whether or not a user was shown the popup asking for a review in shared preferences so that it prevents the app from asking again. But you can't force people to rate your app, only choose not to show them the reminder again

SHartley
  • 37
  • 4
  • I agree. My current method for getting ratings is a little thumbs-up graphic in the action bar. If someone get's curious and taps that a message pops up asking them to rate the app. If the user accepts they are sent to the app in the play store and the thumb vanishes from the action bar. The idea is to not interrupt the user's workflow unless they initiate the process out of curiosity of what the icon is, and by leaving the icon up there is a reminder that it really would be nice of them to rate the app. That hasn't gotten any ratings so I wanted to present a dialog on exiting the app. – Thomas Hodges Sep 14 '15 at 22:34