Reputation: 5020
Friends i have made a location based application.
i have implemented all the code and when my location is changed it calls onLocationChanged method of LocationListener Interface.
I have also used onUpdateLocation() method to get location updates and now i want to pass the lat and long to the activity. How can i do that ??
UPDATED
I know to use Intent . But where should i call the Intent?
I can not call it in onLocationChanged Mthod/
Please Guide
Upvotes: 0
Views: 322
Reputation: 9745
Using Broadcast is much better way, because location info and activities needs to be loosely coupled and passing such data async is safer.
Upvotes: 0
Reputation: 4187
Another solution is to create broadcast receiver inside of the activity. The LocationListener broadcasts a message each time a location is updated. Inside of this message you can put lat and lon values.
Using this way you can update the values dynamically.
Upvotes: 1
Reputation: 653
I use the Intent.
Intent intent = new Intent().setClass(YourActivity.this, YourDestinationActivity.class);
intent.putDoubleExtra("com.example.lat", yourLatValue);
intent.putDoubleExtra("com.example.long", yourLongValue);
startActivity(intent);
Then use
Double d = getIntent().getDoubleExtra("com.example.lat", -1);
in YourDestinationActivity
Upvotes: 0