开发者

How do I handle screen orientation changes with an activity started within a tab's activity

I have a TabActivity, and each Tab corresponds to its own Activity. In one of them, in the onCreate method, I use startActivityForResult to show a dialog (specifically, Bump's BumpAPI activity).

    protected void onCreate(Bundle savedInstanceState) {
    sup开发者_开发技巧er.onCreate(savedInstanceState);
    bump = new Intent(this, BumpAPI.class);
    bump.putExtra(BumpAPI.EXTRA_API_KEY, API_KEY);
    startActivityForResult(bump, BUMP_API_REQUEST_CODE);
}

The problem is that when the screen orientation changes, it tries to create the tab's activity again which makes another BumpAPI dialog, resulting in multiple stacked on top of each other. Do I have a hook into the started activity to cancel the previous one when the orientation changes?

A workaround seems to be to add a button that when clicked, starts the second activity, but that adds an unnecessary step.

Also, I can't fix the screen orientation for the entire tabActivity because some of them require typing and users may want to use their physical keyboards.


Ok I figured it out...pretty simple solution. Just add android:configChanges="orientation|keyboardHidden" to the activity in AndroidManifest. That tells it not to restart the activity for those types of config changes. Only appropriate if you don't have separate layouts for the different orientations, but we luckily did not.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜