Jary
Jary

Reputation: 85

Changing screen orientation issue: onCreate

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?

Upvotes: 2

Views: 3065

Answers (2)

GSree
GSree

Reputation: 2898

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

Upvotes: 2

Cristian
Cristian

Reputation: 200160

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.

Upvotes: 0

Related Questions