Startactivity in navigation drawer

When we want to change Activity we can use:

Intent i = new Intent(this، ActivityTwo.class);‎
startActivity(i);

When i use it in some Activity it work correctly
But it dose not work when I use it in navigation drawer project. I think it dose not work beacuse Test class extends Fragment. in AppCompatActivity it work.

public class Test extends Fragment {
    public Test() {
        // Required empty public constructor
    }
         @Override
            public View onCreateView(LayoutInflater inflater, ViewGroup container,
                                     Bundle savedInstanceState) {

                View v= inflater.inflate(R.layout.fragment_test , container, false);

                button= (Button)  v.findViewById(R.id.button);
                button.setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
              Intent i = new Intent((getActivity(), ActivityTwo.class);‎
              startActivity(i);
                    }
                });
            return v;
        }
}

In my MainActivity I change code:

 public boolean onNavigationItemSelected(MenuItem item) {
        int id = item.getItemId();
        Fragment fragment=null;
        if (id == R.id.nav_camera) {

            Test   contactUsFragment=new Test();
            FragmentManager manager=getSupportFragmentManager();
            manager.beginTransaction().replace(R.id.mainLayout,contactUsFragment).commit();


        } else if (id == R.id.nav_gallery) {

        } else if (id == R.id.nav_slideshow) {

            ActivityTwoss=new ActivityTwo();
            FragmentManager manager=getSupportFragmentManager();
            manager.beginTransaction().replace(R.id.mainLayout,ss).commit();
        }
        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        drawer.closeDrawer(GravityCompat.START);
        return true;
    }

You create a xml container? If so, use a Fragment, not an Activity, for the FragmentManager

In my MainActivity I change code:

public boolean onNavigationItemSelected(MenuItem item) {
    int id = item.getItemId();
    Fragment fragment=null;
    if (id == R.id.nav_camera) {

        Test   contactUsFragment=new Test();
        FragmentManager manager=getSupportFragmentManager();
        manager.beginTransaction().replace(R.id.mainLayout,contactUsFragment).commit();


    } else if (id == R.id.nav_gallery) {

        FragmentManager fragmentManager = getSupportFragmentManager();
        FragmentTransaction transaction = fragmentManager.beginTransaction();
        transaction.add(R.id.fragment_conteiner, new Test(), "Test");
        transaction.commit();

    } else if (id == R.id.nav_slideshow) {

    }
    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    drawer.closeDrawer(GravityCompat.START);
    return true;
}

MainActivity xml

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="br.com.onuse.finds.Activity.MainActivity"
tools:showIn="@layout/fragment_conteiner"
android:id="@+id/fragment_conteiner">

</FrameLayout>

I think you want to start a new Activity from your Fragment using the following sentence:

Intent i = new Intent((getActivity(), ActivityTwo.class);‎
startActivity(i);

Well, that won’t work. You should start your Activity from your current activity (not from your Fragment). You may use something like this:

Intent i = new Intent((getActivity(), ActivityTwo.class);‎
getActivity().startActivity(i);

Or you can do that in one line from your Fragment:

getActivity().startActivity(new Intent(getActivity(), ActivityTwo.class));

Let me know if that works for you!