in my fragment the bundle is always null
main activity
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Bundle args=new Bundle();
args.putString("itemname", "hello");
beaconListFragment=new BeaconListFragment();
beaconListFragment.setArguments(args);
//i don't know if this is needed or not, i tried with and without it
// Add the fragment to the 'fragment_container' FrameLayout
getSupportFragmentManager().beginTransaction().add(R.id.fragmentContainer, beaconListFragment,"tag").commit();
}
...
..
.
BeaconListFragment
public class BeaconListFragment extends android.support.v4.app.Fragment {
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
Bundle bundle = getArguments();
//bundle is always null
if (bundle != null) {
String link = bundle.getString("itemname");
}
}
...
..
.
most examples seem like this but i can't understand where is the problem