Drawing fragment over main activity
<p>I am new to developing android applications, so please pardon any stupid mistakes that I may have made. On to the question:
I am making an application which has its main activity layout screen containing some stuff and have a navigation drawer wired in. Now I am trying to use the entries in the navigation drawer to call up various fragments and display them over my main activity. However when I run my piece of code, I am getting an <em>Activity Destroyed</em> error I have attached my code below for reference. I think the problem is with what I have done with the container. To make the fragment cover the whole screen of my main activity, I gave the fragment container as the root layout as I was unsure how to go about this. </p>

<p>Code which handles item clicks from navigation drawer</p>

<pre><code>class DrawerItemClickListener extends FragmentActivity implements ListView.OnItemClickListener {
@Override
public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long id) {
    selectItem(position);
}

private void selectItem(int position) {
    Fragment mFragment = null;
    switch(position) {
        case 0:
            mFragment = new AnnouncementFragment();
            Bundle args = new Bundle();
            args.putInt(null, position);
            break;
        case 1:
            break;
        case 2:
            break;
        case 3:
            break;
        default:
            break;
    }
    FragmentTransaction transaction = getSupportFragmentManager().beginTransaction().replace(R.id.drawer_layout, mFragment);
    transaction.commit();
    transaction.addToBackStack(null);
}
</code></pre>

<p>Code for fragment</p>

<pre><code>public class AnnouncementFragment extends Fragment {
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    return inflater.inflate(R.layout.fragment_announcement, container, false);
}
</code></pre>

<p>XML layout of main activity</p>

<pre><code>&lt;android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"&gt;

&lt;RelativeLayout
    android:id = "@+id/main_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"&gt;

    &lt;TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/screen_login"
        android:gravity="center"
        android:textColor="@android:color/holo_blue_light"
        android:id="@+id/login_tv"
        android:layout_alignParentTop="true"
        android:layout_marginTop="105dp"
        android:layout_alignParentEnd="true"
        android:layout_alignParentStart="true"
        android:textSize="40sp" /&gt;

    &lt;EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/username_et"
        android:layout_below="@id/login_tv"
        android:layout_alignParentStart="true"
        android:layout_marginTop="45dp"
        android:layout_alignParentEnd="true"
        android:hint="@string/username"/&gt;

    &lt;EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:inputType="textPassword"
        android:ems="10"
        android:id="@+id/editText2"
        android:layout_below="@id/username_et"
        android:layout_alignParentStart="true"
        android:layout_marginTop="30dp"
        android:layout_alignParentEnd="true"
        android:hint="@string/password" /&gt;

    &lt;Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/login"
        android:id="@+id/login_btn"
        android:layout_below="@+id/editText2"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="25dp" /&gt;

&lt;/RelativeLayout&gt;

&lt;ListView
    android:id="@+id/drawer_list"
    android:layout_width="200dp"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:background="#ffeeeeee"/&gt;
</code></pre>

<p>
Error</p>

<pre><code>java.lang.IllegalStateException: Activity has been destroyed
                                                               at android.support.v4.app.FragmentManagerImpl.enqueueAction(FragmentManager.java:1399)
                                                               at android.support.v4.app.BackStackRecord.commitInternal(BackStackRecord.java:637)
                                                               at android.support.v4.app.BackStackRecord.commit(BackStackRecord.java:616)
                                                               at com.it.learnera.DrawerItemClickListener.selectItem(DrawerItemClickListener.java:40)
                                                               at com.it.learnera.DrawerItemClickListener.onItemClick(DrawerItemClickListener.java:19)
</code></pre>

<p>I am wondering how I can make the fragment draw over the main activity layout without causing a mess</p>

<p>Cheers and Thanks in advance</p>