Skip to content

Instantly share code, notes, and snippets.

View noaht11's full-sized avatar

Noah Tajwar noaht11

View GitHub Profile
@noaht11
noaht11 / OC-RestoringStateFragment.java
Last active July 6, 2018 12:52
Where to restore state in a Fragment
private static final String STATE_ID = "id";
private static final String STATE_ITEMS = "items";
private long mId;
private ArrayList<Item> mItems;
private ListView mListView;
private ArrayAdapter<Item> mAdapter;
@Override
@noaht11
noaht11 / OC--SavingStateListViewActivity.java
Last active August 29, 2015 14:27
Saving state for a ListView
private static final String STATE_ITEMS = "items";
// Make sure to declare as ArrayList so it's Serializable
private ArrayList<Item> mItems;
...
@Override
protected void onSaveInstanceState(Bundle outState) {
// Make sure to call the super method so that the states of our views are saved
@noaht11
noaht11 / OC-RestoringStateActivity.java
Last active August 29, 2015 14:27
Restoring very simple state
private static final String STATE_COUNTER = "counter";
private TextView mCounterTextView;
private int mCounter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
...
@noaht11
noaht11 / OC-SavingStateActivity.java
Last active August 29, 2015 14:27
How to save very simple state
private static final String STATE_COUNTER = "counter";
private int mCounter;
...
@Override
protected void onSaveInstanceState(Bundle outState) {
// Make sure to call the super method so that the states of our views are saved
super.onSaveInstanceState(outState);
<activity
android:name=".MyActivity"
android:label="@string/title_my_activity"
android:screenOrientation="portrait" />
@noaht11
noaht11 / OC-ConfigChangesFlag.xml
Last active August 29, 2015 14:27
Using the android:configChanges flag on an activity in AndroidManifest.xml
<activity
android:name=".MyActivity"
android:label="@string/title_my_activity"
android:configChanges="orientation|screenSize|keyboardHidden" />