View activity snippet from another activity

Hello everyone. I want to open the "Text-To-Speech output" fragment from the application settings. First I need to open the settings activity, and then a fragment of it. I tried setting ComponentName but could not find the action.

Should I use a FragmentManager ; I could not find anything specific in my needs. Can someone give me a link that could explain this well.

+6
source share
2 answers

You can use the following:

 Intent ttsSettings = new Intent("com.android.settings.TTS_SETTINGS"); ttsSettings.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(ttsSettings); 
+2
source

You are right, first of all, you need to start an action, and then set the current fragment to FragmentPager / Manager ... This is not such a way to launch any extraneous fragment from your activity, which can be dangerous, as this will lead to zombie fragments will float around the application (or maybe I don’t know about it ..)

  1. You call Intent Activity with some parameter for the fragment name, you want to run, for example, interger, boolean, etc ...

      Intent intent = new Intent(this,SecondActivity.class); intent.putExtra("fragmentNumber",1); //for example startActivity(intent); 
  2. You check the passed value inside OnCreate from Second Acitivty and set the desired fragment on top .. inside OnCreate

      if(getIntent().getIntExtra("fragmentNumber",0)==1){ //set the desired fragment as current fragment to fragment pager } 

However, I have no problem "It was unable to locate the activity." You entered the Activity file in the manifest, what problem did you encounter? Please post the full stack trace.

+15
source

Source: https://habr.com/ru/post/1483572/


All Articles