1

I am trying to force my Android application to go from the onPause method directly to the onResume method by using a dialog.

I have the following code in the onClick method in my FirstActivity class which implements OnClickListener:

Dialog dialog = new Dialog(this);

dialog.setContentView(R.layout.newlayout);
dialog.setTitle("This is my custom dialog box");
dialog.setCancelable(true);
dialog.show();

I've set up each lifecycle method to print out a log message when the Android app enters each method:

Log.i(ActivityName, " onCreate");
Log.i(ActivityName, " onPause");
Log.i(ActivityName, " onResume");

And so on..

When I click my button to show the dialog, the dialog shows up just fine, but I do not receive any log messages that the onPause is being called when showing the dialog and I'm not receiving any log messages that the onResume method is being called when pushing the "back" button on my phone to exit the dialog.

What am I doing wrong?

Birdman
  • 5,244
  • 11
  • 44
  • 65
  • when dialog show at that time your Activity not go in Background or not stop or pause. thats why you did not get any log. read this for more details. http://developer.android.com/reference/android/app/Activity.html – Dhaval Parmar Jul 04 '12 at 09:59

1 Answers1

2

A Dialog is always created and displayed as a part of an Activity(take a look at this article on Dialogs). That's why your Activity methods onResume and onPause are not called. When a Dialog is displayed your Activity is still in running state.

droid8421
  • 895
  • 1
  • 13
  • 26
  • So I have to start a new Activity inside the dialog? – Birdman Jul 04 '12 at 09:57
  • 1
    In that case, yes. Just create a new Activity and declare it as a dialog in your manifest: [Activity as a dialog](http://stackoverflow.com/a/1979631/1328337) – droid8421 Jul 04 '12 at 10:04