Когда я меняю ориентацию с portrait
на landscape
, показанный ArrayList
становится null
.Когда я запускаю в режиме landscape
, все работает нормально, но когда я переключаюсь на portrait
и обратно на landscape
, данный список массивов становится null
.Я передаю данные, используя bundles
.Я использую 2 макета, если это помогает.
Как видно из журнала, ArrayList, полученный в методе getArgs, не является нулевым, но все же, тот же ArrayList становится нулевым в onActivityCreated.Когда я снова переключаюсь на Портрет, все работает как надо.Я понятия не имею, что происходит.
public class ListFrag extends Fragment {
RecyclerView recyclerview;
RecyclerView.Adapter myadapter;
RecyclerView.LayoutManager layoutManager;
View view;
ArrayList<Subject> subjects;
public ListFrag() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
Log.d(TAG, "onCreateView: Fragment created");
view= inflater.inflate(R.layout.fragment_list, container, false);
return view;
}
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
recyclerview =view.findViewById(R.id.list);
recyclerview.setHasFixedSize(true);
layoutManager = new LinearLayoutManager(this.getActivity());
recyclerview.setLayoutManager(layoutManager);
if(subjects==null) {
subjects= new ArrayList<>();
Log.d(TAG, "onActivityCreated: Subjects is null");
subjects.add(new Subject("New Subject"));
}
myadapter = new SubjectAdapter(this.getActivity(), subjects);
recyclerview.setAdapter(myadapter);
}
//This is a bundle from the main activity, it contains the local subjects //ArrayList.
public void getArgs(Bundle args){
subjects= args.getParcelableArrayList("arraylist");
Log.d(TAG, "getArgs: Bundle Recieved");
if(subjects!=null)
Log.d(TAG, "getArgs: "+subjects.get(1).getSub_name());
}
}
Я показываю журнал, когда меняю ландшафт <-> портрет <-> пейзаж.Как можно видеть, когда ориентация является альбомной во второй раз, объекты ArrayList становятся нулевыми.
D/Constraints: onCreateView: Fragment created
D/Constraints: getArgs: Bundle Recieved
D/Constraints: getArgs: PCE // There is no subjects is null log i.e. working as expected.
W/Activity: Slow Operation: Activity com.kinshuu.silverbook/.MainActivity onCreate took 573ms
I/Adreno: QUALCOMM build : cf57c9c, I1cb5c4d1cc
Build Date : 09/23/18
OpenGL ES Shader Compiler Version: EV031.25.03.01
Local Branch :
Remote Branch :
Remote Branch :
Reconstruct Branch :
Build Config : S L 6.0.7 AArch64
I/Adreno: PFP: 0x005ff112, ME: 0x005ff066
I/ConfigStore: android::hardware::configstore::V1_0::ISurfaceFlingerConfigs::hasWideColorDisplay
retrieved: 0
android::hardware::configstore::V1_0::ISurfaceFlingerConfigs::hasHDRDisplay retrieved: 0
I/OpenGLRenderer: Initialized EGL, version 1.4
D/OpenGLRenderer: Swap behavior 2
I/Choreographer: Skipped 62 frames! The application may be doing too much work on its main thread.
I/OpenGLRenderer: Davey! duration=1356ms; Flags=0,
IntendedVsync=97223951567176, Vsync=97224984900468,
OldestInputEvent=9223372036854775807, NewestInputEvent=0,
HandleInputStart=97224993787166, AnimationStart=97224993944978,
PerformTraversalsStart=97224996071280, DrawStart=97225005895864,
SyncQueued=97225058785291, SyncStart=97225058907843,
IssueDrawCommandsStart=97225059050708, SwapBuffers=97225304631072,
FrameCompleted=97225307792895, DequeueBufferDuration=8842000,
QueueBufferDuration=955000,
I/shuu.silverboo: ProcessProfilingInfo new_methods=10 is saved saved_to_disk=1 resolve_classes_delay=8000
W/shuu.silverboo: Accessing hidden field Lsun/misc/Unsafe;->theUnsafe:Lsun/misc/Unsafe; (light greylist, reflection)
W/Activity: Slow Operation: Activity com.kinshuu.silverbook/.MainActivity onPause took 227ms
D/Constraints: onCreateView: Fragment created
D/Constraints: getArgs: Bundle Received
getArgs: PCE //changed to portrait for the first time, nothing surprising here.
I/Choreographer: Skipped 58 frames! The application may be doing too much work on its main thread.
I/OpenGLRenderer: Davey! duration=1046ms; Flags=0,
IntendedVsync=97235972493579, Vsync=97236939160207,
OldestInputEvent=9223372036854775807, NewestInputEvent=0,
HandleInputStart=97236951083724, AnimationStart=97236951267578,
PerformTraversalsStart=97236953417578, DrawStart=97236962640547,
SyncQueued=97237012391797, SyncStart=97237012495547,
IssueDrawCommandsStart=97237012607734, SwapBuffers=97237017997109,
FrameCompleted=97237019035807, DequeueBufferDuration=2937000,
QueueBufferDuration=532000,
D/Constraints: onCreateView: Fragment created
D/Constraints: getArgs: Bundle Received
D/Constraints: getArgs: PCE//subjects is not null
D/Constraints: onActivityCreated: Subjects is null // And subjects is null at the same time.
I/Choreographer: Skipped 33 frames! The application may be doing too much work on its main thread.}