سؤال

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?

هل كانت مفيدة؟

المحلول

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.

نصائح أخرى

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

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top