Move data from one Activity to Fragment in android

// At your acticity add this code Bundle bundle = new Bundle(); bundle.putString("tag",searchTerm); Fragment searchfragment = new SearchFragment(); searchfragment.setArguments(bundle); FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction(); fragmentTransaction.replace(R.id.contanerall,squadFragment,null); fragmentTransaction.commit(); // Then at your fragment String text=this.getArguments().getString("tag");

4 Responses

isn't it better to implement communicator pattern on activity and using getters and setters from activity to fragments.
@Faisal Naseer I didn't know this way can you share it with me ?
Have look at the documentation. https://developer.android.com/training/basics/fragments/communicating.html
If it fell short do lemme know.

Write a comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.