问题
i have an app with various fragments and the problem is when the phone rotates, the app displays other fragments from the begining. it does not close the current fragments but looks like layers on top of each other. any help i'd be grateful. thanks
回答1:
Try this to add in your AndroidManifest
<Activity
....
....
android:configChanges="orientation|screenSize">
回答2:
You need to check for a savedInstanceState, and if it exists, don't re-create your fragments. just check if is null or not
as shown below
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
if (savedInstanceState == null) {
// Do your oncreate because there is no bundle
}else{
// Do that needs to be done even if there is a saved instance, or do nothing
}
}
check this for more detail.
来源:https://stackoverflow.com/questions/34504679/disable-other-fragments-in-auto-rotation