-
Notifications
You must be signed in to change notification settings - Fork 1.3k
GPS on/off state is not persisted #911
Comments
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. |
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
|
@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. |
^^ 👍 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);
} |
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?
The text was updated successfully, but these errors were encountered: