Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Because you construct a new Bundle so it can retrieve the datas you saved in your activity.</p> <p>You can implement the following :</p> <pre><code>public class MyLocationListener implements LocationListener{ Bundle bundle = new Bundle(); public Bundle getBundle(){ return bundle; } @Override public void onLocationChanged(Location location) { // TODO Auto-generated method stub lat = location.getLatitude(); lon = location.getLongitude(); Toast.makeText(ourContext, lat +" ve "+ lon, Toast.LENGTH_LONG).show(); bundle.putString("lat", lat.toString()); bundle.putString("lon", lon.toString()); } //other method } public class MyLocation{ private LocationManager locationManager; LocationListener locationListener; private Context ourContext; public MyLocation(Context context){ this.ourContext = context; locationManager = (LocationManager) context.getSystemService(context.LOCATION_SERVICE); locationListener = new MyLocationListener(); boolean gps = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER); if(!gps){ locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 6000, 100, locationListener); AlertDialog alertDialog = new AlertDialog.Builder(context).create(); alertDialog.setTitle("GPS Disabled"); alertDialog.setMessage("You can enable GPS for settings"); alertDialog.setIcon(R.drawable.ic_launcher); alertDialog.show(); } else { locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 6000, 100, locationListener); } public Bundle getBundle(){ if(locationListener != null) return locationListener.getBundle(); else return null; } } </code></pre> <p>Then just do :</p> <pre><code> Bundle bundle = myLocation.getBundle(); if(bundle != null){ tv1.setText("Lon : " + bundle.getString("lon")); tv2.setText("Lat : " + bundle.getString("lat")); } </code></pre> <p><strong>EDIT :</strong></p> <p>Change <code>private LocationListener locationListener;</code></p> <p>with <code>private MyLocationListener locationListener;</code></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload