Avoiding fragment duplicates (App crushes due to the id property of the fragment)
<p>There can be several instances of the same Activity in the task. My problem is that when I declare header-fragment like this:</p>

<pre><code>    &lt;fragment 
    android:name="fragments.TabletHeader"
    android:layout_width="match_parent"
    android:layout_height="56dp"
    android:id="@+id/header" /&gt;
</code></pre>

<p>it stumbles on the second creation of the same activity. This is, I guess, because this  static declaration forces system to create second insance of the same fragment which is not allowed. Am I right ? </p>

<p>What are the tactics for solving this issue. Essentially I need to switch to the dynamic approach but how do I find out whether fragment already exists. Show me some examples, please.</p>

<p>Here's the backtrace:</p>

<pre><code>07-17 14:34:34.593: E/AndroidRuntime(15546): android.view.InflateException: Binary XML file line #7: Error inflating class fragment
07-17 14:34:34.593: E/AndroidRuntime(15546):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:697)
07-17 14:34:34.593: E/AndroidRuntime(15546):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:739)
07-17 14:34:34.593: E/AndroidRuntime(15546):    at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
07-17 14:34:34.593: E/AndroidRuntime(15546):    at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
07-17 14:34:34.593: E/AndroidRuntime(15546):    at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
07-17 14:34:34.593: E/AndroidRuntime(15546):    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:273)
07-17 14:34:34.593: E/AndroidRuntime(15546):    at android.app.Activity.setContentView(Activity.java:1835)
07-17 14:34:34.593: E/AndroidRuntime(15546):    at android.activity.MainActivity$1.dispatchMessage(MainActivity.java:112)
07-17 14:34:34.593: E/AndroidRuntime(15546):    at android.os.Looper.loop(Looper.java:137)
07-17 14:34:34.593: E/AndroidRuntime(15546):    at android.app.ActivityThread.main(ActivityThread.java:4514)
07-17 14:34:34.593: E/AndroidRuntime(15546):    at java.lang.reflect.Method.invokeNative(Native Method)
07-17 14:34:34.593: E/AndroidRuntime(15546):    at java.lang.reflect.Method.invoke(Method.java:511)
07-17 14:34:34.593: E/AndroidRuntime(15546):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
07-17 14:34:34.593: E/AndroidRuntime(15546):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
07-17 14:34:34.593: E/AndroidRuntime(15546):    at dalvik.system.NativeStart.main(Native Method)
07-17 14:34:34.593: E/AndroidRuntime(15546): Caused by: java.lang.IllegalArgumentException: Binary XML file line #7: Duplicate id 0x7f08000e, tag null, or parent id 0x0 with another fragment for android.fragments.TabletHeader
07-17 14:34:34.593: E/AndroidRuntime(15546):    at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:275)
07-17 14:34:34.593: E/AndroidRuntime(15546):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:669)
07-17 14:34:34.593: E/AndroidRuntime(15546):    ... 14 more
</code></pre>
