There is activity, from it you need to go to fragment. This line does not want to work:

intent = new Intent(MainMenu.this, Service.class).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
  • What is what in the above piece of code? MainMenu - what is it? Activity , Fragment ? And Service ? - falstaf
  • From Activity to Fragment, means MainMenu - Activity, Service - Fragment. In my menu there are both activations and fragments, on activations from activations, I know how to go, how to go from activations to fragments - no. - Imire
  • Well, to put it mildly, the class names are not at all obvious. And the Service class, which in fact is not a service at all, but a fragment (and even the name makes confusion with the class of the same name from the SDK) is generally beyond good and evil. Use appropriate suffixes, at least. - falstaf
  • Ok, in the future I will write correctly. MainMenu is my ListView, I switch from it to different classes. There are activations and fragments. - Imire

1 answer 1

Intent to open the Activity used, to go to the fragment you must use the FragmentManager .

 FragmentManager fragmentManager = getFragmentManager() FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); ExampleFragment fragment = new ExampleFragment(); fragmentTransaction.add(R.id.fragment_container, fragment); fragmentTransaction.commit(); 

Read off. documentation