Darksymphony
Darksymphony

Reputation: 2683

Android MapsActivity - onclick reload activity

I have a google map in MapsActivity with 3 clickable buttons. Each button shows different markers on the map.

This is achieved via:

 public void AllMap(View v) //first button
{
    SharedPreferences mypref = PreferenceManager.getDefaultSharedPreferences(this);
    SharedPreferences.Editor prefsEditr = mypref.edit();
    prefsEditr.putInt("mapselect", 1);
    prefsEditr.apply();

    finish();
    Button button = findViewById(R.id.allmap);
    button.setCompoundDrawablesWithIntrinsicBounds( 0, R.drawable.allmapon, 0, 0);
    button.setTextColor(Color.parseColor("#ff5722"));
    startActivity(getIntent());
}

And then on Map setup I read the SharedPreferences and according to the selected option I add Markers on the map.

This is working fine, but after I click, the whole activity reloads but it seems like a right to left slide animation. So the new reloaded activity comes from right side of device.

I have no animations or something like that set, but seems this is default behavior for all my activities on my device. However it seems not very good in MapsActivity. Is there a way to refresh the MapsActivity without restarting it - so just the markers will change?

What should I call instead of finish(); startActivity(getIntent()); ?

Upvotes: 1

Views: 297

Answers (1)

Pavneet_Singh
Pavneet_Singh

Reputation: 37404

What should I call instead of finish(); startActivity(getIntent()); to refresh map?

You can clear all the existing marker by invoking mMap.clear() and add the markers again according to new shared preference values.

Or

You can keep the references of your marker in arralist or something so that you can change their locations in map

Upvotes: 2

Related Questions