Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

GPS on/off state is not persisted #911

Closed
ljbade opened this issue Feb 20, 2015 · 4 comments
Closed

GPS on/off state is not persisted #911

ljbade opened this issue Feb 20, 2015 · 4 comments
Labels
Android Mapbox Maps SDK for Android bug

Comments

@ljbade
Copy link
Contributor

ljbade commented Feb 20, 2015

Currently when you rotate the Android app the GPS on/off state is not saved.

Best solution is to use a ToggleButton which persists it's state instead of the manual toggle I have:
http://stackoverflow.com/questions/14958197/is-it-possible-to-implement-toggle-button-in-action-menu-item-using-actionbar-sh

@bleege Are you familiar with the Action Bar?

@ljbade ljbade added bug Android Mapbox Maps SDK for Android labels Feb 20, 2015
@ljbade ljbade added this to the Android Beta milestone Feb 20, 2015
@bleege
Copy link
Contributor

bleege commented Feb 23, 2015

This looks like it just needs to persist the state of a UI widget across a rotation correct? If so, this is traditionally handled via Activity.onSaveInstanceState() and Activity.onRestoreInstanceState(). Google provides a good overview for how to do this. This method is universal to the entire Activity so it'd work for ActionBars, Widgets, and custom drawables.

@mb12
Copy link

mb12 commented Feb 23, 2015

To handle rotation and keyboard configuration changes, just make the following changes.

1.) In your AndroidManifest.xml add android:configChanges="keyboardHidden|orientation"


..............

2.) Add this on your activity

public void onConfigurationChanged(Configuration arg0) {
    super.onConfigurationChanged(arg0);
} 

@ljbade
Copy link
Contributor Author

ljbade commented Feb 23, 2015

@mb12 I used to handle rotation, but I purposefully don't handle it now. The reason is we have no control over how the end apps that use MapView handle configuration changes so we should make sure we support restarting the activity on rotation.

@bleege I was going to use the normal instance state saving but I don't know how to get a reference to the toolbar button to set it's icon (which indicates if GPS is on or off), except in the on click listener method.

@bleege
Copy link
Contributor

bleege commented Feb 23, 2015

I used to handle rotation, but I purposefully don't handle it now. The reason is we have no control over how the end apps that use MapView handle configuration changes so we should make sure we support restarting the activity on rotation.

^^ 👍

The items that appear in the Navbar are actually set via the Menu API. In this case the GPS button is defined here in menu_main.xml in the GLTestApp. The easiest way to get / keep access is to save a reference to the MenuItem when the Menu is initially inflated and added to the UI. In this case something like:

    // New reference to the GPS Menu Item
    private MenuItem gpsMenuItem;

    // Adds items to the action bar menu
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.menu_main, menu);
        // Find the GPS MenuItem and store a reference to it for later use
        gpsMenuItem = (MenuItem)menu.findItem(R.id.action_gps);
        return super.onCreateOptionsMenu(menu);
    }

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Android Mapbox Maps SDK for Android bug
Projects
None yet
Development

No branches or pull requests

3 participants