I am working with a navigation drawer on a MainActivity and then I am using this navigation drawer to replace different fragments int the container of the MainActivity. In Fragment I am using Google Map. In this fragment I am also using the Ion library to download some location information from the server and to show them on the map.
The navigation drawer items are Home ,friends location , about us
now when I click on friend location I want to draw pins on the map , so I am u using the same map of the home screen as home screen is also showing map.
What I am doing on Friends location item click is as under
myMapFragment = new MyMapFragment();
fragmentTransaction1.replace(R.id.frame, myMapFragment, "MyMapFragment").commit();
fragmentManager.executePendingTransactions();
myMapFragment.GetAllFriendsLocation("share",MainActivity.this);
so the GetAllFriendsLocation is the method in that fragment which is showing map and this function is downloading location information from server and then draw pins on the map
this is how I am doing this
public void GetAllFriendsLocation(String type) {
MainActivity.setOverflowButtonColor(getActivity(),2);
if(cd.isConnectingToInternet()) {
progressDialog.show();
Ion.with(getActivity())
.load("http://myapi.com/data.php")...
but I am getting nulpointerException on the following line
Ion.with(getActivity()) .load("http://myapi.com/data.php").
it seems like that getActivity is empty as the fragment is not fully initiated.
So please give me advises that how can I call the fragment method when it is initialized and ready to show on the screen , after when it is initialized the method should run and download from server.
or second this i can think of is , How can I get context in mainactiivty before the fragment is initialized ???
please help me in this ..