mvasco
mvasco

Reputation: 5107

Intent between activities is not working

In my app I am using intents to pass objects from an activity to another activity.

In this case, I am passing values to be used as map markers on the second activity.

From the source activity, I am using the following method to open the second activitiy:

public void openMapa(View view){

         //Starting single contact activity
        Intent in = new Intent(getApplicationContext(),
                Empresas_Mapa.class);
        Log.v("LATITUD EN EMPRESAS SIMPLE", latitudEmpresa);
        in.putExtra(TAG_NOMBREEMPRESA, nombreEmpresa);
        in.putExtra(TAG_DIRECCIONEMPRESA, direccionEmpresa);
        in.putExtra(TAG_LATITUDEMPRESA, latitudEmpresa);
        in.putExtra(TAG_LONGITUDEMPRESA, longitudEmpresa);


        startActivity(in);


    }

To check that the passing values are right, you may see a log, which shows the expected value for latitudEmpresa.

And this is the code for the second activity:

public class Empresas_Mapa extends Activity{

    static final LatLng CANARIAS = new LatLng(27.9405285, -15.5566901);

      private GoogleMap map;

    String nombreEmpresa;
    String direccionEmpresa;
    String latitudEmpresa;
    String longitudEmpresa;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.mapa_activity_main);

        Intent i = getIntent();
        nombreEmpresa = i.getStringExtra("TAG_NOMBREEMPRESA");
        direccionEmpresa = i.getStringExtra("TAG_DIRECCIONEMPRESA");
        latitudEmpresa = i.getStringExtra("LATITUDEMPRESA");
        longitudEmpresa = i.getStringExtra("LONGITUDEMPRESA");
        Log.v("LATITUD EN EMPRESAS MAPA", latitudEmpresa);
        map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map))
                .getMap();



         // Move the camera instantly to hamburg with a zoom of 15.
            map.moveCamera(CameraUpdateFactory.newLatLngZoom(CANARIAS, 15));

            // Zoom in, animating the camera.
            map.animateCamera(CameraUpdateFactory.zoomTo(10), 2000, null);
            map.setMyLocationEnabled(true); //

            Marker marker = map.addMarker(new MarkerOptions()

            .title(nombreEmpresa)
             .position(new LatLng(
                 Double.parseDouble(latitudEmpresa),
                 Double.parseDouble(longitudEmpresa)

             ))
             .snippet(direccionEmpresa)
             .icon(BitmapDescriptorFactory
            .fromResource(R.drawable.ofertas))
        );
    }


}

But the intent is not passing and getting anything.

Any help is welcome.

Upvotes: 0

Views: 72

Answers (1)

codeMagic
codeMagic

Reputation: 44571

You are checking for the wrong value. You are using the value to check when you should be checking the key (first param in putExtra())

For instance, here you are using the value you want to pass

latitudEmpresa = i.getStringExtra(""LATITUDEMPRESA"");

but this is wrong. Assuming the key you set is static, you would check with

latitudEmpresa = i.getStringExtra(ActivityOneName.TAG_LATITUDEMPRESA);

You aren't using a key named, "LATITUDEMPRESA". You are passing with a key of TAG_LATITUDEMPRESA. So the Intent is passing the data but you aren't retrieving it appropriately.

Upvotes: 1

Related Questions