android-configchanges

Why does onLayout and onSizeChanged get called twice on an orientation change?

吃可爱长大的小学妹 提交于 2019-12-30 08:15:07
问题 I've noticed that onLayout and onSizeChanged get called twice in immediate succession after an orientation change, either from landscape->portrait or from portrait->landscape, when handling the configuration change from an Activity. Furthermore, the first onLayout/onSizeChanged contain the old dimensions (before the rotate), while the 2nd onLayout/onSizeChanged contain the new (correct) dimensions. Does anyone know why, and/or how to work around this? It seems like perhaps the screen size

Restore Android GridView after screen orientation change (without reloading it)

試著忘記壹切 提交于 2019-12-23 04:55:24
问题 I'm new to Android (this is my first application) and I made a GridView in an Activity which I'd like it to be responsive according to screen position (portrait / landscape). Of course I made some custom layout values of GridView rows width for portrait as well as for landscape, and it works perfect. Except that, on every screen orientation change, the GridView is reloading again. And that's not good for user experience. I only like the GridView (and definitely its rows) to adjust to new

onSaveInstanceState() vs. onRetainCustomNonConfigurationInstance()

杀马特。学长 韩版系。学妹 提交于 2019-12-22 09:59:17
问题 I am using ActionBarSherlock, along with several MenuItem s that I dynamically manage, depending on program state. Specifically, I save the MenuItem s into instance variables in the Activity 's onCreateOptionsMenu() method, and then can show and/or hide them as needed later in the Activity . However, I found that the MenuItem variables can be lost on configuration changes, such as device rotation. So I also put them into a Parcel and pass them to onSaveInstanceState() for restoral through the

Fragment recreated every time after orientation change, unable to restore state

做~自己de王妃 提交于 2019-12-22 04:32:38
问题 Update: It turns out that the problem is from elsewhere. Thanks @Luksprog for pointing out what I overlooked. The project is created using Android Studio's navigation drawer pattern. The drawer is implemented in the NavigationDrawerFragment class. The fragment holding the view pager is added when a particular item in the drawer is selected. The code is implemented my home activity. When screen rotates, the onCreate() method of NavigationDrawerFragment is called, preserving last selected item.

Older devices and AndroidManifest configChanges “screenSize”

你说的曾经没有我的故事 提交于 2019-12-13 02:08:23
问题 Quoting the documentation: Caution: Beginning with Android 3.2 (API level 13), the "screen size" also changes when the device switches between portrait and landscape orientation. Thus, if you want to prevent runtime restarts due to orientation change when developing for API level 13 or higher (as declared by the minSdkVersion and targetSdkVersion attributes), you must include the "screenSize" value in addition to the "orientation" value. That is, you must decalare android:configChanges=

UI updates across config changes: The weird point

只愿长相守 提交于 2019-12-11 17:55:09
问题 I am an experienced Android developer and it is a shame that I am still ineffectively fighting against fundamental issues like persisting UI changes across configuration changes. I know, this is an all too well known problem and there exists a lot of literature on it. The recommended solution is to setRetainInstance(true) a UI-less fragment: https://www.androiddesignpatterns.com/2013/04/retaining-objects-across-config-changes.html Best practice: AsyncTask during orientation change For the

RecyclerView is in the middle instead of top after orientation changes from landscape to portrait

混江龙づ霸主 提交于 2019-12-11 12:19:29
问题 I have used recyclerview in a fragment. If activity's configChanges includes orientation, recycler view appears in the middle of the screen after phone orientation changes from landscape to portrait. However it should be on top always. If configChanges does not include orientation, it always appear on top on orientation changes. Do you have any idea what it is the reason? This is the activity layout <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk

How to setup night mode drawables to work as expected

不羁的心 提交于 2019-12-10 21:39:34
问题 I what to change background as night mode changes. I have /values and /values-night folder, that contain "colors.xml" with different values. ` <color name="grey1">#ebebeb</color> <color name="grey2">#c7c7c7</color> <color name="grey3">#999999</color> <color name="hover1">#8bb065</color> <color name="red1">#ba0000</color> <color name="red2">#ff0000</color> <color name="green1">#336600</color> <color name="text1">#000000</color> and other is <color name="grey1">#999999</color> <color name=

Non-UI Fragment vs Singleton

自闭症网瘾萝莉.ら 提交于 2019-12-10 12:42:23
问题 I guess that the main purpose of the non-UI fragments is the storage of data that is retained over configuration changes, right? So, appart from being this storage specific for the Activity that owns this fragment, which is the benefit of its usage over a Singleton pattern across the entire application (which is the solution I've been doing so far)? 回答1: The fact that a fragment is scoped to its activity means there is less chance of a long-term memory leak, as opposed to singletons -- the

How to get android video capture to survive screen rotation

Deadly 提交于 2019-12-10 11:13:27
问题 I have managed to get Video capture to work for a custom camera experience (i.e. using MediaRecorder, Camera, SurfaceView, etc.). But if I am recording a video and change the orientation of the device, video capture stops. Is there way to continue the capture after the orientation change? If fact I want the capture to continue no matter how many times the orientation changes. I imagine it might all have to do with savedInstanceState and saving the file that I pass to mRecorder.setOutputFile