2

I have an issue when changing my screen orientation. I have an activity with 2 intents that gets called by a service.

When I rotate the screen, going into landscape mode, it recalls onCreate. The issue is I have a button, and TextField which gets updated through a handler), and they don't seem to react anymore.

Like this is the code when I try also to add the button in the onCreate but it doesn't respond once the view is changed to landscape mode:

public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.call);

  Button endCall = (Button) findViewById(R.id.stopCall);
  endCall.setOnClickListener(new View.OnClickListener() {
   @Override
   public void onClick(View v) {
    /// ...
   }
  });

  handleIntent(getIntent());
 }

How do people treat this reorientation please? Is there a way to have it not recall onCreate please or what is the most common way to treat this case please?

Cristian
  • 198,401
  • 62
  • 356
  • 264
Jary
  • 85
  • 3
  • 7
  • 2
    This is probably the most asked android question. When you change orientations, the activity gets destroyed and recreated. Just search on here for orientation changes and you'll find many solutions. – Falmarri Dec 05 '10 at 02:10
  • Thanks. I used android:configChanges="orientation|keyboardHidden" in the Manifest and it's fixed. Thanks a lot. – Jary Dec 05 '10 at 06:39

2 Answers2

2

See this documentation for best practice. configChanges is a short term solution http://android-developers.blogspot.com/2009/02/faster-screen-orientation-change.html

savageBum
  • 282
  • 1
  • 4
  • 11
GSree
  • 2,890
  • 1
  • 23
  • 25
0

In your case, what you have to do is to stop the handler on onDestroy, so that it can be re-executed again in onCreate.

Cristian
  • 198,401
  • 62
  • 356
  • 264
  • Thanks for your response, sorry I am a little confused. Can you please explain what you mean by stop the handler please? – Jary Dec 05 '10 at 01:35