开发者

Changing screen orientation issue: onCreate

I have an issue when changing my screen orientation. I hav开发者_如何学JAVAe 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?


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜