1

I am developing a small app which shows passwords of the user through a Dialog screen.

When home button is pressed, I need to dim the screen (on the multi tasking window) so that any other person cannot see the password.

When user re-opens the app, it asks an application lock. But if the user leaves the password Dialog open and presses the home button, dialog and the password which user last looked at stays visible (on the multi tasking window) for a while (3-4 seconds!!) until a new dialog asks the lock.

So far I tried ever possible dialog.dissmiss() options. Dialog dismisses only when app is opened again (until a new lock dialog appears) even I put dismiss() in onPause, onStop etc.

Any idea appreciated.

I also tried,

android.os.Process.killProcess(android.os.Process.myPid());
this.finish();
System.exit(0);

none of them actually worked.

Ry-
  • 218,210
  • 55
  • 464
  • 476
user2226106
  • 23
  • 1
  • 5

1 Answers1

0

Suggestion 1: Double-check your implementation. Tying your dialog to the activity lifecycle seems like a good idea (especially to avoid leaked window errors as described here)

The following example works out well for me (with coachMark being derived from Dialog)

@Override
protected void onResume()
{
    log.debug("onResume");
    super.onResume();

    // Show the coachMark depending on saved preference values
    coachMark.mayBeShow();
}

@Override
protected void onPause()
{
    log.debug("onPause");

    // Hide the coachMark if it is showing to avoid leakedWindow errors
    coachMark.maybeHide();

    super.onPause();
}

onPause definately gets called when you press the home button, so if this approach does not work for you, try not recreating the dialog in the restarting part of the acitivty lifecycle (onRestart(), onStart() and onResume()) and see, if it gets dismissed correctly.


Suggestion 2: Should all of the above fail, you might consider overriding the home button as described here. I highly advise against it though, since this may cause the app to work in an way that the user does not expect it to.

Community
  • 1
  • 1
Father Stack
  • 524
  • 3
  • 10
  • Yes I traced the log and like you said onPause() gets called when home button pressed. I removed the recreation of dialog onStart() and call dismiss() onPause. When home button pressed, app directly goes to background and I can still see the dialog (in the multitasking window of course). Also, dismissing is so slow, like 3 seconds. And I can still see the dialog when app reopened during 3 secs. – user2226106 Jul 20 '13 at 14:23