-5

In my second activity there is coding of to find current location, but i want to display that location on my first activity text view. So, plz help me. here is my code of second activity in which I find my current location and below this code I paste my First activity coding on which i want to display my current location

public class Trackme extends Activity implements OnMapClickListener {

TextView tv;
GoogleMap googleMap = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.trackme);
    tv=(TextView)findViewById(R.id.textView1);

    initilizeMap();
    googleMap.setOnMapClickListener(this);
}

private void initilizeMap()
{
    try{
    if (googleMap == null) 
    {
        MapFragment fr = ((MapFragment) getFragmentManager().findFragmentById(
                R.id.map));

        googleMap = fr.getMap();

        googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
        googleMap.setMyLocationEnabled(true);

    }
    }catch(Exception ex)
    {

        Toast.makeText(this, ex.getMessage(), Toast.LENGTH_LONG).show();
    }

}

@Override
public void onMapClick(LatLng arg1)
{
    try{
    LocationManager mngr = (LocationManager)getSystemService(LOCATION_SERVICE);
    Geocoder g =new Geocoder(this, Locale.getDefault());
    List<Address> l = g.getFromLocation(arg1.latitude, arg1.longitude, 1);
    for(Address adr : l)
    {
        String countyName = adr.getLocality();
        String countyCode = adr.getAddressLine(0);
        String c=adr.getAdminArea();
        String location="Country is ::  "+countyName+" Country Code :: "+countyCode+"state="+c;

        tv.setText(location);
        Toast.makeText(this,"Country is ::  "+countyName+" Country Code :: "+countyCode+"state="+c, Toast.LENGTH_LONG).show();

        Intent i= new Intent(this,RegisterNext.class);
        i.putExtra("a",location);
         setResult(RESULT_OK, i);
        startActivityForResult(i,1);
        finish();


    /*MarkerOptions mrkop = new MarkerOptions();
    mrkop.position(new LatLng(arg1.latitude, arg1.longitude));
    mrkop.title(countyName);
    googleMap.addMarker(mrkop);*/
    }
    }catch(IOException ex)
    {

        Toast.makeText(this, ex.getMessage(), Toast.LENGTH_LONG).show();
    }

}

}

Community
  • 1
  • 1
  • Can you please post some code, and clarify what you are trying to say? What is the textview you're referring to? What is the activity you're talking about? Please post more details. – Henry98 Aug 15 '15 at 03:43
  • http://stackoverflow.com/questions/4233873/how-to-get-extra-data-from-intent-in-android/4233941#4233941 – NickT Aug 15 '15 at 03:46
  • I posted my code above, from this code I get my current location on this activity but i want to display it on my previous activity – Chirag Aggarwal Aug 15 '15 at 04:12
  • [Going back to previous Activity with different value](http://stackoverflow.com/questions/18243515/android-going-back-to-previous-activity-with-different-intent-value/18243541#18243541) also, if I understand you correctly, you don't want to call `finish()` in your first Activity – codeMagic Aug 21 '15 at 14:59

1 Answers1

-2

Dude go through maps api on android.developer website. Through your second activity send the result back to the 1st one using intents.