-
Notifications
You must be signed in to change notification settings - Fork 229
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[ASNETutorial]Application always crashing after changing orientation (rotating device) #47
Comments
check it, thanks. Forgot about it in ASNETutorial app. |
This looks to be a bug in ASNE rather than just the tutorial. This same exception also occurs when replacing fragments in an activity. For example, say I have a home activity that can open either a login fragment or a signup fragment. If I open the signup fragment, press back, then go to the login fragment, any requestLogin() call will cause the same null pointer. If it is any help, I've verified this behavior doesn't occur using the Android Social Networks library ASNE was based off. |
@ITurchenko Here is a workaround that may help for the time being. This worked for me.
On your orientation change, remove the old asne fragment and create a new one. executePendingTransactions() must be used to make sure the old one is removed before the new created. Hope this helps. |
I think the issue is the way that the context is passed.
On orientation changed or a replaced fragment, the original "this" fragment context that is passed is stale. |
Is this bug already fixed? |
I found another way to avoid crash and memory leaks (use this code in your fragment): ...
private SocialNetworkManager snm;
...
@Override
public void onResume() {
super.onResume();
if (null == snm || snm.getInitializedSocialNetworks().isEmpty()) initSocialManager();
}
@Override
public void onPause() {
super.onPause();
if (isRemoving() || getActivity().isFinishing()/* or check for change rotation event*/) {
if (null != snm && snm.isAdded()) getFragmentManager().beginTransaction().remove(snm).commit();
snm = null;
}
}
... |
Hello again.
How to reproduce bug:
Open example project (https://github.com/gorbin/ASNETutorial) on device, rotate device at least once and then press any of the social buttons.
Result for facebook:
For VKontakte will be something like
after finishing fragment.
The text was updated successfully, but these errors were encountered: