Skip to content

Instantly share code, notes, and snippets.

@robUx4
Created July 18, 2013 13:02
Show Gist options
  • Save robUx4/6029108 to your computer and use it in GitHub Desktop.
Save robUx4/6029108 to your computer and use it in GitHub Desktop.
Safe Fragment class
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