I have an Activity A that loads fragments based on a menu selection. If I make an intention from Activity B to Activity A, the default fragment of Activity A will load. I want to achieve loading another fragment from Activity A instead of the standard one. Hope this at least makes sense. I tried to do it β
In action B, I have β
btnlinkToForum.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { Intent i = new Intent(getApplicationContext(), ReaderActivity.class); i.putExtra("fragmentNumber", 1); startActivity(i); } });
And I'm trying to use putExtra data to load a specific fragment in Activity A, like this -> I put this code in the onCreate method
if (getIntent().getIntExtra("fragmentNumber", 0) == 1) { FragmentManager fm = ReaderActivity.this.getSupportFragmentManager(); FragmentTransaction ft = fm.beginTransaction(); FragmentForum fragment = new FragmentForum(); if (fragment != null) { // Replace current fragment by this new one ft.replace(R.id.activity_main_content_fragment, fragment); ft.commit(); // Set title tvTitle.setText("Forum"); } }
This, however, loads the default snippet ... Any help would be greatly appreciated
android android-intent fragment
user3004164
source share