Answer the question
In order to leave comments, you need to log in
How to send data from activity to fragment?
I am getting data from activity1 into this activity2, and I want to send the received information to the fragment that is in activity2.
activity2
public class HeroPage extends AppCompatActivity {
ImageView picture;
String heroNameInPage;
public static final String heroNameInPage_KEY = "heroNameInPage";
FragmentManager fm = getSupportFragmentManager();
Fragment infoFragment;
Bundle getHeroName;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_hero_page);
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.hide();
}
if (savedInstanceState == null){
getSupportFragmentManager().beginTransaction().replace(R.id.frameLayout, new InfoFragment()).commit();
}
getHeroName = getIntent().getExtras();
TextView textView = findViewById(R.id.text1);
if (getHeroName != null) {
heroNameInPage = getHeroName.getString(Heroes.heroName_KEY);
textView.setText(heroNameInPage);
/*infoFragment = fm.findFragmentById(R.id.frameLayout);
Bundle setHeroName = new Bundle();
setHeroName.putString(heroNameInPage_KEY, heroNameInPage);
infoFragment.setArguments(setHeroName);*/
}
}
}
/*Bundle bundle = this.getArguments();
if (bundle != null) {
heroNameInFragment = bundle.getString(HeroPage.heroNameInPage_KEY);*/
Answer the question
In order to leave comments, you need to log in
Applications "crash" with a specific error and stacktrace. Look in LogCat.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question