II. The specified child already has a parent. You must call removeview () on the child's parent F

Source: Internet
Author: User

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();} 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.