2

I've created a dialog but according to the activity workflow it should trigger the onpause but it doesn't. What is going wrong? Android Activity Flow : http://developer.android.com/training/basics/activity-lifecycle/pausing.html

    @Override
    public boolean onOptionsItemSelected(MenuItem item)
    {
        //stopAutoCall = true;
        // Handle item selection
        // if (item.getTitle().toString().toLowerCase() == "settings")
        // {
        AlertDialog.Builder alert = new AlertDialog.Builder(this);

        alert.setTitle("Number");
        alert.setMessage("Put here the number in to call");

        alert.show();
    }

    @Override
    public void onPause()
    {
        super.onPause();

        stopAutoCall = true;
    }
VRC
  • 745
  • 7
  • 16

3 Answers3

5

A dialog isn't actually supposed to pause the activity. You're probably confused by this sentence.-

During normal app use, the foreground activity is sometimes obstructed by other visual components that cause the activity to pause. For example, when a semi-transparent activity opens (such as one in the style of a dialog), the previous activity pauses

Which talks about a new activity opening, in the style of a dialog, but not a dialog.

However, if you want to trigger some code whenever your dialog opens, you could use onShowListener.-

alert.setOnShowListener(new DialogInterface.OnShowListener() {      
    @Override
    public void onShow(DialogInterface dialog) {
        stopAutoCall = true;
    }
});
ssantos
  • 16,001
  • 7
  • 50
  • 70
0

This code will just display the alert but it won't cause onPause.

onPause will get called when the activity is becoming hidden by another activity, not an alert. An alert still belongs to the same activity.

Szymon
  • 42,577
  • 16
  • 96
  • 114
0

The API of Activity has a better definition:

OnPause

Called as part of the activity lifecycle when an activity is going into the background, but has not (yet) been killed. The counterpart to onResume().

Your doubts about partially visible are not caused because of a dialog, looking at your link you can find:

When the system calls onPause() for your activity, it technically means your activity is still partially visible, but most often is an indication that the user is leaving the activity and it will soon enter the Stopped state.

AlexBcn
  • 2,450
  • 2
  • 17
  • 28