android control back button while a dialog is on the screen

I have a timer which runs continously. When I press the BACK button I made a dialog to appear where you can quit from that intent or go back and cointinue the timer what has been stopped by the BACK button. Well if I click on the contimnue, the onResume() method makes the timer continue and it works good. But, if I press the back button when the dialog is on the screen I want the timer to go on just like if I press the Continue on the dialog. But instead, I press the back button and nothing happens, the timer is stopped and it is not good for me since some of my methods only works if the timer is going or it is stopped by the dialog. But if there is no dialog and the timer is stopped numerous potential errors can happen. So how can I stop the user to press the back button when the dialog is on the screen? I tried something like this:

if ((keycode==back) && a=0 ) {... a=1 , onPuase()}  // dialog comes in onPause() just happened
else ((keycode==back) && a=1 ) {... a=0, onResume()}  //I want onResume() to happen here  

But it is not good. The dialog appears on the first Back button then it disappears on the second Back (nothing happens here). The timer is still stopped here however the third back button starts the timer. So there is an unecessary Back which can cause troubles since the useres wont know that they have to press it again...

Answers


A few advices:

  1. Do not call onResume/onPause manually, only system should make it. Else you'll have unexplainable issues on various devices.
  2. You really want to use OnDismissListener ( http://developer.android.com/reference/android/content/DialogInterface.OnDismissListener.html ). As starting from ICS, dialog can be dismissed not only by pressing Back key, but also by tapping somewhere on screen, outside the dialog.
  3. If you want to prevent dismissing the dialog by "back" and "tapping out of dialog" - use setCancellable(false) http://developer.android.com/reference/android/app/Dialog.html#setCancelable(boolean) for the dialog.

Good luck


If you want to be notified when user pressed BACK while your dialog was displayed, use OnDismissListener


implement OnDismissListener in your DialogClass

and override OnDismiss method

    @Override
public void onDismiss(DialogInterface dialog) {
    super.onDismiss(dialog);
    //you can control back button from here 
}

Need Your Help

Assembly define variable in .code (MASM)

variables assembly masm

Is there any way to create a variable in the .code section, instead of .data? I simply feel limited, in that I can't make a variable on the fly.

Going from Android to iOS in PhoneGap

android ios cordova porting

How does PhoneGap work? (I'm still going through all their faqs, etc.) I downloaded the andriod sdk and installed PhoneGap stuff and also got the Hello World working on the Android emulator. Now ho...