I wrote an application that requires different la s to be displayed on the portrait and landscape screens.
if (this.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {setNormalHorizontalView();} else if (this.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {setNormalVerticalView();}
Activitymanager is used to switch views during portrait display.
mFrameLayout.removeAllViews();switch(mPresentActivity){case 0:mFrameLayout.addView((mLocalActivityManager.startActivity("", new Intent(GinwaveIMusic.this,GinwavePlayer.class)).getDecorView()));break;case 1:mFrameLayout.addView((mLocalActivityManager.startActivity("", new Intent(GinwaveIMusic.this,Album.class)).getDecorView()));break;case 2:mFrameLayout.addView((mLocalActivityManager.startActivity("", new Intent(GinwaveIMusic.this,GinwaveMusic.class)).getDecorView()));break;case 3:mFrameLayout.addView((mLocalActivityManager.startActivity("", new Intent(GinwaveIMusic.this,PlayList.class)).getDecorView()));break;}
The specified child already has a parent will appear when you switch from the portrait screen to the landscape screen and then switch to the portrait screen. you must call removeview () on the child's parent first. as prompted, I have added mfamelayout. removeallviews () function, but this problem still occurs. I think it may be because mlocalactivitymanager has been executed during the portrait screen. startactivity ("", new intent (ginwaveimusic. this, ginwaveplayer. class )). the getdecorview () method executes this method after the screen is converted from the landscape to the landscape. After the first switch, the view is not released, therefore, when I switch from a portrait screen to a landscape screen, this view is released. After I add the following code in onconfiguration, there is no problem.
if (this.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {if(mFrameLayout != null){mFrameLayout.removeAllViews();}setNormalHorizontalView();}