I have an activity, which is getting some string from other activity:
public class ShowPoints extends AppCompatActivity {
public String points;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_show_points);
Intent i = getIntent();
points = i.getStringExtra("geoPoints");
}
}
That works.
From this activity ShowPoints
, I want to send the received string points
to its fragment called PointsOnMap
For that, I created the fragment PointsOnMap
and did this:
public class PointsOnMap extends Fragment implements OnMapReadyCallback {
......
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
act = new ShowPoints();
String points = act.points;
mView = inflater.inflate(R.layout.activity_points_on_map, container, false);
return mView;
}
But the String points
of the fragment PointsOnMap
its never filled with the string coming from the activity ShowPoints
.
I am wondering what I am doing wrong. I have read some other posts here and seems like I am doing it in the right way.
----EDIT----
The last edits I did on the code seems not to work, I am pretty sure the problem is in the part where I am passing the parameters, since, without parameters passing, everything works and the initial map is showed.
so until now, the activity that contains the class is like this:
public class ShowPoints extends AppCompatActivity {
public String points;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_show_points);
Intent i = getIntent();
points = i.getStringExtra("geoPoints");
PointsOnMap pointsOnMapFragment = new PointsOnMap();
Bundle bundle = new Bundle();
bundle.putString("geoPoints",points);
pointsOnMapFragment.setArguments(bundle);
Log.d("REACHED HERE","---------");
}
}
And the part of the fragment where i am retrieving the passed string is like this:
public class PointsOnMap extends Fragment implements OnMapReadyCallback {
......
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
Bundle args = getArguments();
geopoints = args.getString("geoPoints");
mView = inflater.inflate(R.layout.activity_points_on_map, container, false);
return mView;
}
It is still not working for some reason.....The traceback indicates null object reference
on the fragment on line geopoints = args.getString("geoPoints");