Skip to content

Commit

Permalink
Merge pull request #1027 from Teovald/3.0
Browse files Browse the repository at this point in the history
Catch IllegalStateException in onAttach for v3
  • Loading branch information
sjudd committed Mar 4, 2016
2 parents 1a10191 + ac3b33a commit 82209f7
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import android.app.Activity;
import android.app.Fragment;
import android.os.Build;
import android.util.Log;

import com.bumptech.glide.RequestManager;

Expand All @@ -23,6 +24,9 @@
*/
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public class RequestManagerFragment extends Fragment {

private static final String TAG = "RMFragment";

private final ActivityFragmentLifecycle lifecycle;
private final RequestManagerTreeNode requestManagerTreeNode = new FragmentRequestManagerTreeNode();
private RequestManager requestManager;
Expand Down Expand Up @@ -114,10 +118,18 @@ private boolean isDescendant(Fragment fragment) {
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
rootRequestManagerFragment = RequestManagerRetriever.get()
.getRequestManagerFragment(getActivity().getFragmentManager());
if (rootRequestManagerFragment != this) {
rootRequestManagerFragment.addChildRequestManagerFragment(this);
try {
rootRequestManagerFragment = RequestManagerRetriever.get()
.getRequestManagerFragment(getActivity().getFragmentManager());
if (rootRequestManagerFragment != this) {
rootRequestManagerFragment.addChildRequestManagerFragment(this);
}
} catch (IllegalStateException e) {
// OnAttach can be called after the activity is destroyed, see #497.
if (Log.isLoggable(TAG, Log.WARN)) {
Log.w(TAG, "Unable to register fragment with root", e);

}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.annotation.SuppressLint;
import android.app.Activity;
import android.support.v4.app.Fragment;
import android.util.Log;

import com.bumptech.glide.RequestManager;

Expand All @@ -20,6 +21,9 @@
* @see com.bumptech.glide.RequestManager
*/
public class SupportRequestManagerFragment extends Fragment {

private static final String TAG = "SupportRMFragment";

private RequestManager requestManager;
private final ActivityFragmentLifecycle lifecycle;
private final RequestManagerTreeNode requestManagerTreeNode =
Expand Down Expand Up @@ -113,10 +117,18 @@ private boolean isDescendant(Fragment fragment) {
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
rootRequestManagerFragment = RequestManagerRetriever.get()
.getSupportRequestManagerFragment(getActivity().getSupportFragmentManager());
if (rootRequestManagerFragment != this) {
rootRequestManagerFragment.addChildRequestManagerFragment(this);
try {
rootRequestManagerFragment = RequestManagerRetriever.get()
.getSupportRequestManagerFragment(getActivity().getSupportFragmentManager());
if (rootRequestManagerFragment != this) {
rootRequestManagerFragment.addChildRequestManagerFragment(this);
}
} catch (IllegalStateException e) {
// OnAttach can be called after the activity is destroyed, see #497.
if (Log.isLoggable(TAG, Log.WARN)) {
Log.w(TAG, "Unable to register fragment with root", e);

}
}
}

Expand Down

0 comments on commit 82209f7

Please sign in to comment.