0

I'm still relatively new to Android. I'm working on a map based app and want to incorporate an old map fragment and inflate it into a new activity.

In terms of the intent, I only want to send a double latitude and double longitude to the new activity and I have written some code to work from those values alone.

But I want the transition between activities to be seamless (with a few button additions. I don't want to make new fragments if I don't have to.

My onCreate method in the starting activity is like so:

    @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_maps);
    SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
            .findFragmentById(R.id.map_activity);
    mapFragment.getMapAsync(this);

}

and there is a button in which the onClick method sends the LatLng doubles to a new Activity. The onCreate for the second activity is the following:

 @Override
protected void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_circle_size);
    SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
            .findFragmentById(R.id.map_activity);
    mapFragment.getMapAsync(this);
    double latitude = this.getIntent().getDoubleExtra("SEND_LATITUDE", 0);
    double longitude = this.getIntent().getDoubleExtra("SEND_LONGITUDE", 0);
    circleSize(latitude, longitude);

}

As you can see, I'm trying to use the same fragment from the layout with SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager() .findFragmentById(R.id.map_activity);

Do I have the correct approach here?

Thank you

-T

TJBlack31
  • 745
  • 4
  • 8
  • 23
  • What do you mean by "old map fragment"? Do you have existing code that you need to use in your project? – Daniel Nugent Mar 18 '17 at 18:16
  • @DanielNugent Well I recently learned that you can't pass objects with intents, only primitives. So I would like to inflate the fragment from the first activity (the one that triggers the intent) into the second one and pass lat/long data as extras. – TJBlack31 Mar 18 '17 at 18:20
  • For using a SupportMapFragment directly in an Activity, see here: http://stackoverflow.com/questions/34582370/how-can-i-show-current-location-on-a-google-map-on-android-marshmallow – Daniel Nugent Mar 18 '17 at 18:24
  • If you want to have the map functionality in a Fragment, see here: http://stackoverflow.com/questions/41753706/show-current-location-inside-google-map-fragment – Daniel Nugent Mar 18 '17 at 18:25
  • 1
    Also, you can pass certain Objects through intents, if they implement the Parcelable interface. You could pass a LatLng object through the intent, see here: http://stackoverflow.com/questions/16134682/how-to-send-a-latlng-instance-to-new-intent – Daniel Nugent Mar 18 '17 at 18:29
  • @DanielNugent Thank you! I'll give this a shot tomorrow – TJBlack31 Mar 19 '17 at 07:28

0 Answers0