3

In my application I am showing an Alert dialogue and its getting closed when the screen orientation changes. How to solve this ? My code is given below.

private void showDialogue() {
    AlertDialog.Builder alert = new AlertDialog.Builder(MyClass.this);
    alert.setTitle("Title");
    alert.setIcon(R.drawable.icon);
    LayoutInflater inflater = (LayoutInflater)MyClass.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View view = inflater.inflate(R.layout.dialogue, null, false);
    EditText from= (EditText)view.findViewById(R.id.from);
    EditText to= (EditText)view.findViewById(R.id.to);
    from.setHint("eg : From");
    to.setHint("eg : To");
    alert.setView(view);
    searchAlert = alert.create();
    searchAlert.show();
}
Mohsin Naeem
  • 12,542
  • 3
  • 39
  • 53
user965071
  • 1,643
  • 5
  • 16
  • 16

2 Answers2

0

It's normal cause the Activity was destroyed and Created once more. You can see this question Android - Dealing with a Dialog on Screen Orientation change it should help.

Community
  • 1
  • 1
Gorets
  • 2,434
  • 5
  • 27
  • 45
0

When orientation changes, the activity is destroyed and created again.

To understand the lifetimes of activity's check this video: http://www.youtube.com/watch?v=fL6gSd4ugSI -Android basic video 2.

Then you should figure out how you are gonna save the information package and reinitialize it when the create of the activity is called.

Which can all be found in the documentation.

Tristan
  • 342
  • 2
  • 13