Last active
August 29, 2015 14:14
-
-
Save mths0x5f/aef09db983810325c6d9 to your computer and use it in GitHub Desktop.
Using a Fragment to retain object instances on device configuration changes - Android
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
| /* | |
| * Created on base of this tutorial: | |
| * http://developer.android.com/guide/topics/resources/runtime-changes.html#RetainingAnObject | |
| * Licensed under Apache License 2.0, as the Official Android Documentation | |
| * | |
| */ | |
| package com.example.myapplication.util; | |
| import android.app.Fragment; | |
| import android.os.Bundle; | |
| /** | |
| * This class makes preserving object instances on configuration change easy | |
| * @param <T> Generic type of the object | |
| */ | |
| public class DataFragment<T> extends Fragment { | |
| private T data; | |
| @Override | |
| public void onCreate(Bundle savedInstanceState) { | |
| super.onCreate(savedInstanceState); | |
| setRetainInstance(true); | |
| } | |
| public void setData(T data) { this.data = data; } | |
| public T getData() { return data; } | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
An important note from documentation: