Last active
August 29, 2015 14:22
-
-
Save patrickhammond/9b54a5e82e07c5a265c0 to your computer and use it in GitHub Desktop.
Work in progress...
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MyActivity extends Activity { | |
private static final String STATEFUL_COUNT = “count”; | |
private int count; | |
@Override | |
public void onCreate(Bundle savedInstance) { | |
super.onCreate(savedInstanceState); | |
if (savedInstanceState != null) { | |
count = savedInstanceState.getInt(STATEFUL_COUNT); | |
} else { | |
count = 1; | |
} | |
... normal activity stuff ... | |
} | |
@Override | |
public void onSaveInstanceState(Bundle outState) { | |
super.onSaveInstanceState(outState); | |
outState.put(STATEFUL_COUNT, count); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MyActivity extends Activity { | |
@Stateful(initial=1) | |
private int count; | |
@Override | |
public void onCreate(Bundle savedInstance) { | |
super.onCreate(savedInstanceState); | |
... normal activity stuff (state has already been restored) ... | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
It is save to ignore this file if you are just reading sample code!!! | |
onCreate(savedInstanceState) { | |
super.onCreate(savedInstanceState) | |
(( "injected" state magic )) | |
... useful implementation | |
} | |
onSaveInstanceState(out) { | |
super.onSaveInstanceState(out) | |
(( "injected" state magic )) | |
... optional interesting implementation (otherwise explicit onSaveInstanceState is not required) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
It is save to ignore this file if you are just reading sample code!!! | |
(( "injected" state magic )) | |
onCreate(savedInstanceState) { | |
super.onCreate(savedInstanceState) | |
... useful implementation | |
} | |
onSaveInstanceState(out) { | |
super.onSaveInstanceState(out) | |
... optional interesting implementation (otherwise explicit onSaveInstanceState is not required) | |
} | |
(( "injected" state magic )) <-- Not perfect due to potential of state clobbering. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment