The specified child already has a parent. You must call removeView() on the child's parent first.

by Dikers » Fri, 14 Nov 2008 09:50:19 GMT


Sponsored Links
 I want to start 'MultiActivity' from 'OtherActivity' that in another
application,
and when I back to homescreen (don't close 'MultiActivity' ),  start
'MultiActivity' again,
need to save the state of 'MultiActivity'.

but when running in
         backLayout.updateViewLayout(backgroundView, blp);
         setContentView(backLayout);

Something has gone wrong.


java.lang.IllegalStateException: The specified child already has a
parent. You must call removeView() on the child's parent first.

   at android.view.ViewGroup.addViewInner(ViewGroup.java:1785 )
   at android.view.ViewGroup.addView(ViewGroup.java:1680)
   ......
   at com.android.internal.policy.impl.PhoneWindow.setContentView
(PhoneWindow.java:261)
   at android.app.Activity.setContentView(Activity.java:1581)

Does anyone know what's wrong with this app,
Thanks in advance!




-----------------------
MultiActivity.class------------------------------------

private static AbsoluteLayout backLayout  = null;
private static ImageView backgroundView = null;


public void onCreate(Bundle icicle){

        super.onCreate(icicle);

        LayoutParams blp = new AbsoluteLayout.LayoutParams( 200, 300,  0, 0);

        if(backLayout==null){

                backgroundView =  new ImageView(this);
                backgroundView.setImageResource(R.drawable.background);


                backLayout = new AbsoluteLayout(this);
                backLayout.addView(backgroundView,  blp);
                setContentView(backLayout);

        }else {

                backLayout.updateViewLayout(backgroundView, blp);
                setContentView(backLayout);// occur exception.

        }

                //
                Intent intent = getIntent();
                if( intent.hasExtra("data")){
                        String data = intent.getStringExtra("data");
                        doSomething(data);
                }


}
-------------------------------------------------------------------------



------------------------
AndroidManifest.xml----------------------------------
 <activity android:name=".MultiActivity" android:theme="@android:style/
Theme.Dialog"  android:label="@string/app_name">
            <intent-filter>

                <action android:name="android.intent.action.VIEW" />
                <category
android:name="android.intent.category.DEFAULT" />
                <data android:mimeType="vnd.android.cursor.item/
vnd.dikers.test" />

            </intent-filter>
        </activity>
-------------------------------------------------------------------------------




---------------------OtherActivity.class  in another
application.---------------------
        Intent intent = new Intent();

        intent = new Intent(Intent.ACTION_VIEW);
        intent.setType("vnd.android.cursor.item/vnd.dikers.test");
        intent.putExtra("data", "data");
        startActivity(intent);
--~--~---------~--~----~------------~-------~--~----~



The specified child already has a parent. You must call removeView() on the child's parent first.

by gsmd » Sun, 15 Mar 2009 22:18:04 GMT


 This is the IllegalStateException thrown from onCreate() that brings
the main activity of my app down upon restart (e.g. launch app -> hit
back -> launch again -> got it).
Could someone elaborate on what does this exception mean?
--~--~---------~--~----~------------~-------~--~----~


Sponsored Links


Other Threads

1. Change Tab Background <selector>

Hi guys,

a simple question: how to change the TabBackground in the different
states (not the icon!) ?

my files:

tabindicator.xml

<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="false"
      android:state_selected="false"
      android:state_pressed="false"
      android:drawable="@drawable/tab_focus"/>
<item android:state_focused="false"
      android:state_selected="true"
      android:state_pressed="false"
      android:drawable="@drawable/tab_focus"/>
<item android:state_focused="true"
      android:state_selected="false"
      android:state_pressed="false"
      android:drawable="@drawable/tab_focus"/>
<item android:state_focused="true"
      android:state_selected="true"
      android:state_pressed="false"
      android:drawable="@drawable/tab_focus"/>
<item android:state_pressed="true"
      android:drawable="@drawable/tab_press"/>
</selector>

where should i call the xml file above???

i tried it in the TabWidget as src, but it doesn't work:

<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/tabhost"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <LinearLayout
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:src="@layout/tabindicator"> // look here
        </TabWidget>
        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent">
        </FrameLayout>
    </LinearLayout>
</TabHost>

So i tried to use a own theme:

<?xml version="1.0" encoding="utf-8"?>
<resources>
        <style name="tab" parent="android:Theme.Light">
                <item name="android:tabWidgetStyle">@style/tabindicatorstyle</
item>
        </style>
        <style name="tabindicatorstyle" parent="@android:style/
Widget.TabWidget">
                <item name="android:???">@layout/tabindicator</item>
        </style>
</resources>

but i don't know, which resource i should use instead of "???"...

can anyone help me?

many thanks in advancde!

king regards!

--~--~---------~--~----~------------~-------~--~----~

2. How to debug crash on rotate

I have an application that crashes when the phone is rotated.
It is based on the quickconnect framework.
Sorry for the vagueness of this  message, but how would I begin to
debug what is happening?
What should I look for? How do I gather a trace?

It seems the crash comes at the onSuspend event.

Thanks for any ideas.

-Mike

--~--~---------~--~----~------------~-------~--~----~

3. Still no paid apps in Android Market for Belgium

4. Solution suggestions

5. Still no paid apps in Android Market for Belgium

6. WebView Catch 22 - Same Window, Except For New Domain]

7. intent filter issue