Tutorial by Examples

As your activity begins to stop, the system calls onSaveInstanceState() so your activity can save state information with a collection of key-value pairs. The default implementation of this method automatically saves information about the state of the activity's view hierarchy, such as the text in an...
Fragments also have a onSaveInstanceState() method which is called when their state needs to be saved: public class MySimpleFragment extends Fragment { private int someStateValue; private final String SOME_VALUE_KEY = "someValueToSave"; // Fires when a configuration ch...
In many cases, we can avoid problems when an Activity is re-created by simply using fragments. If your views and state are within a fragment, we can easily have the fragment be retained when the activity is re-created: public class RetainedFragment extends Fragment { // data object we want to ...
If you want to lock the screen orientation change of any screen (activity) of your android application you just need to set the android:screenOrientation property of an <activity> within the AndroidManifest.xml: <activity android:name="com.techblogon.screenorientationexample.Main...
If your application doesn't need to update resources during a specific configuration change and you have a performance limitation that requires you to avoid the activity restart, then you can declare that your activity handles the configuration change itself, which prevents the system from restartin...
Problem: If after the AsyncTask starts there is a screen rotation the owning activity is destroyed and recreated. When the AsyncTask finishes it wants to update the UI that may not valid anymore. Solution: Using Loaders, one can easily overcome the activity destruction/recreation. Example: ...
It is very common that during development, one may find very useful to lock/unlock the device screen during specific parts of the code. For instance, while showing a Dialog with information, the developer might want to lock the screen's rotation to prevent the dialog from being dismissed and the cu...

Page 1 of 1