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
1158

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

阿神
阿神

闭关修行中......

reply all(2)
巴扎黑

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
  1. Activity manages Fragment

  2. How
  3. Fragment manages View

  4. How
  5. 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.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template