android - When the phone is in landscape or portrait mode, the instance in the fragment such as the recyclerview object is null, and the callback when returning data in the background causes a null pointer exception.
阿神2017-05-31 10:38:57
0
2
1117
When the mobile phone switches between horizontal and vertical screens, the fragment status is lost, causing a null pointer exception to be reported when the data callback requested by the child thread is displayed. How to solve it
It feels like screen rotation triggers redrawing. Try adding the following attributes to the current Activity in Manifast: android:configChanges="orientation|screenSize"
Whether you are rotating the screen or closing Activity, you should cancel the response monitoring of the network interface when Fragment#onDestroy() or Fragment#onDestroyView(). Otherwise, even if it is solved by setting android:configChanges When the screen is rotated, Activity is rebuilt and causes the App to crash. Other scenarios may still cause the App to crash.
It is recommended to read the Android source code to understand the following knowledge points:
How
Activity manages Fragment
How
Fragment manages View
How
Activity & Fragment manage Loader
It is also recommended to use Retrofit + RxAndroid + RxLifecycle to implement network interfaces and calls. For page data management, you can consider Loader.
It feels like screen rotation triggers redrawing. Try adding the following attributes to the current Activity in Manifast:
android:configChanges="orientation|screenSize"
It is recommended to read the Android source code to understand the following knowledge points:
How
How
How
Activity
managesFragment
Fragment
managesView
Activity
&Fragment
manageLoader
It is also recommended to use Retrofit + RxAndroid + RxLifecycle to implement network interfaces and calls. For page data management, you can consider
Loader
.