android


How to display the previous map zoom level after finishing the current map in android


I have two maps that are displaying one after the other. Let the activites be Map1 and Map2. First I am displaying the Map1 and then going to Map2 from Map1. Whenever I click on the back button on Map2 I am finishing the Map2 and going to the Map1.
But here the issue is the Map1 is getting the same zoom level as Map2. In the Map1 I am displaying a Marker for the specified address and in the Map2 I am displaying the current location. Both are different MapViews. Can anyone tell me how I can fix this?
When you start the second map activity, save the zoom level as an extra in the intent. Then load it in the second map activity and set the zoom level accordingly.
Saving in the first map activity:
Intent map2Intent = new Intent(this, Map2Activity.class);
map2Intent.putExtra("zoomLevel", mapView.getZoomLevel());
startActivity(map2Intent);
Loading in the second:
Bundle extras = getIntent().getExtras();
if (extras != null) {
int zoom = extras.getInt("zoomLevel");
mapView.setZoomLevel(zoom);
}
EDIT:
After re-reading your question, I realize I misunderstood. To get the same zoom level in Map 1 after returning from Map 2, you could save the value in SharedPreferences, like this
SharedPreferences settings = getPreferences(0);
SharedPreferences.Editor editor = settings.edit();
editor.putInt("zoomLevel", mapView.getZoomLevel());
editor.commit();
then start the activity with startActivityForResult(Intent, REQUEST_CODE where REQUEST_CODE is an integer you use later to identify where you are coming back from. Now implement the onActivityResult method:
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case CHANGE_BUILDING:
SharedPreferences settings = getPreferences(0);
mapView.setZoomLevel(settings.getInt("zoomLevel", 0));
}
}

Related Links

onLocationChanged not being called (using PendingIntent)
Can't open video stream from Android native code with cv::VideoCapture
change ImageView Resource in a ListView Layout from an AsyncTask that load contactsList
How to add border to button in android
Response code 200 from facebook
How to bind the distance between two Markers to my polyline?
Pass argument to constructor from Intent
Universal functions for showing date and time in any locale separately
Using animation set, animation does not happen sequentially
ListView item with dynamic layout(Imageview, TextView)
Eclipse sometimes won't let me set libraries for projects
Viewpager in a fragment
Wondering how Arrayadapter work
Check file before to download
My SQL statement does not return any data from table in android with SQLite
Moving files within SD card

Categories

HOME
service-worker
google-cloud-platform
oracle12c
cobalt
apache-spark-mllib
jsf-2.2
vscode-extensions
seo
dojo
vsm
mvc5
retrofit2
fosrestbundle
syntaxnet
watson-conversation
mautic
datastage
selenium-ide
scrolltop
libusb
mathprog
oledb
apache2.4
simpleitk
object-storage
dapper-extensions
8051
exchangewebservices
jwplayer6
linq-to-objects
visa
datacachefactory
parser-generator
avcapturedevice
show-hide
uiimage
sonarlint-eclipse
tf
lightning
podscms
aquamacs
semantic-logging
headless
donations
change-tracking
watch-os-2
phpwebsocket
blitline
tfs-workitem
oracle-spatial
sony-lifelog-api
rdflib
diff3
mmwormhole
openbabel
infosphere-spl
dbaccess
jbake
strawberry-perl
trdion2011
wxformbuilder
jquery-slider
twitter-bootstrap-rails
qscrollarea
script#
nebula
diem
apache-abdera
boost-signals
appjs
kqueue
fsevents
android-holo-everywhere
cuteeditor
cac
vs-android
maven-1
java1.4

Resources

Encrypt Message