I recently started Android Development, I wanted to create a form by which I also take user address. In the address field I placed a button to choose their location by using map, I successfully get location but the problem is when I return back to main activity all my fields become empty such as name,phone,email e.t.c.
I want that all my fields remain filled after selecting map location
Here is my Main Activity
public class MainActivity extends AppCompatActivity {
private EditText Name, Phone, Destination;
private Button mBtnAdd;
private String type = "1";
TextView textView;
LocationManager locationManager;
String lattitude,longitude;
private static final int REQUEST_LOCATION = 1;
private static final String TAG = "MainActivity";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Name = (EditText) findViewById(R.id.name);
Phone = (EditText) findViewById(R.id.phone);
Destination = (EditText) findViewById(R.id.destinationAddress);
Intent i = getIntent();
String address = i.getStringExtra ( "address");
Destination.setText(address);
}
private void pickup() {
Intent intent = new Intent(MainActivity.this, MapsActivity.class);
intent.putExtra ( "map_type", "1" );
startActivity(intent);
}
}
Here Is my select location Function in main Map Activity
public void updateLocation(View view) throws IOException {
final EditText location = (EditText) findViewById(R.id.name);
LatLng center = mMap.getCameraPosition().target;
Log.e(TAG, "Center: " + center);
Geocoder geocoder;
List<Address> addresses;
geocoder = new Geocoder(this, Locale.getDefault());
addresses = geocoder.getFromLocation(center.latitude, center.longitude, 1); // Here 1 represent max location result to returned, by documents it recommended 1 to 5
Log.e(TAG, "addresses: " + addresses);
String address = addresses.get(0).getAddressLine(0);
Intent i = getIntent();
Intent intent = new Intent( MapsActivity.this, MainActivity.class );
intent.putExtra ( "address", address );
startActivity(intent);
}