Created
July 18, 2013 13:02
-
-
Save robUx4/6029108 to your computer and use it in GitHub Desktop.
Safe Fragment class
This file contains 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
package com.levelup.touiteur; | |
import android.os.Bundle; | |
import android.support.v4.app.Fragment; | |
import android.view.LayoutInflater; | |
import android.view.View; | |
import android.view.ViewGroup; | |
public abstract class FragmentTransactionSafe extends Fragment { | |
private boolean mCanDoTransaction = true; | |
abstract protected View onCreateView(LayoutInflater inflater, Bundle savedInstanceState, ViewGroup root); | |
@Override | |
public void onStart() { | |
super.onStart(); | |
mCanDoTransaction = true; | |
} | |
/* (non-Javadoc) | |
* @see android.support.v4.app.Fragment#onSaveInstanceState(android.os.Bundle) | |
*/ | |
@Override | |
public void onSaveInstanceState(Bundle outState) { | |
super.onSaveInstanceState(outState); | |
mCanDoTransaction = false; | |
} | |
public boolean canDoTransaction() { | |
return mCanDoTransaction; | |
} | |
@Override | |
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { | |
mCanDoTransaction = true; | |
return onCreateView(inflater, savedInstanceState, container); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment