Open a fragment of an activity from another activity

99封情书 提交于 2019-12-05 06:42:13

You can use the following:

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

You are right, First You need to start the Activity than set the current Fragment in FragmentPager / Manager... Their is no such way to start some foreign fragment from your Activity that would be dangerous see that will lead to zombie fragments floating around the App (or May be I am not aware of that..)

  1. You call the Activity Intent with some parameter for the Fragment name, you want to start i.e. 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 of the 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 am not getting the problem "It was unable to locate the activity." Have you entered the Activity in manifest file than what was the problem you were facing? Please post the full stack trace.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!