title: How to open or launch a Fragment from another Activity?
body: <p>from the adapter of a RecyclerView which is contained in an Activity, i'm trying to launch a fragment when an element of the RecyclerView is pressed, this is my code right now :</p>
  
  <pre><code>@Override
  public void onClick(View v) {
      Intent intent;
  
      int position = getAdapterPosition();
  
      SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
      String onoff = preferences.getString("it's", "");
  
      if (onoff.equalsIgnoreCase("on")) {
          if (position == 0) {
  
              CategoriesRecyclerView.fragSubreddit = "aww";
  
              intent = new Intent(context, MainFragment.class);
              context.startActivity(intent);
          }
  
          if (position == 1) {
  
              CategoriesRecyclerView.fragSubreddit = "food";
  
              intent = new Intent(context, MainFragment.class);
              context.startActivity(intent);
          }
  
          if (position == 2) {
  
              CategoriesRecyclerView.fragSubreddit = "funny";
  
              intent = new Intent(context, MainFragment.class);
              context.startActivity(intent);
          }
  
          if (position == 3) {
  
              CategoriesRecyclerView.fragSubreddit = "gaming";
  
              intent = new Intent(context, MainFragment.class);
              context.startActivity(intent);
          }
  
      } else if (onoff.equalsIgnoreCase("off")) {
  
          if (position == 0) {
  
              CategoriesRecyclerView.fragSubreddit = "gaming";
              intent = new Intent(context, MainFragment.class);
              context.startActivity(intent);
          }
  
          if (position == 1) {
  
              CategoriesRecyclerView.fragSubreddit = "funny";
              intent = new Intent(context, MainFragment.class);
              context.startActivity(intent);
          }
  
          if (position == 2) {
  
              CategoriesRecyclerView.fragSubreddit = "food";
              intent = new Intent(context, MainFragment.class);
              context.startActivity(intent);
          }
  
          if (position == 3) {
  
              CategoriesRecyclerView.fragSubreddit = "aww";
              intent = new Intent(context, MainFragment.class);
              context.startActivity(intent);
          }
      }
  }
  </code></pre>
  
  <p>I Tested it launching some "testing activities" that i created, so i know that everything but the fragment launching works fine.</p>
  
  <p>The error is here :</p>
  
  <pre><code>intent = new Intent(context, MainFragment.class);
  context.startActivity(intent);
  </code></pre>
  
  <p>I'm launching the Fragment as it was an Activity, so when i run the app it crashes and tells me to declare the MainFragment as an activity in my manifest.</p>
  
  <p>How can i launch that Fragment from my Activity?</p>
  
  <p>Thanks very much.</p>