1. Fragment (XXFragment) not attached to Activity is abnormal. This exception occurs because when the Fragment has not been Attach to the Activity, the getResource () function is called and the context Content function is required. The solution is to write the called code in OnStart. There are several such references on the Internet: the http://stackoverflow.com/questions/10919240/fragment-myfragment-not-attached-to-activity answers primarily when calling getResources (). getString (R. string. app_name );
Before adding a judgment isAdded (), there is a http://stackoverflow.com/questions/6870325/android-compatibility-package-fragment-not-attached-to-activity for both sides to say this exception solution
This is an alternative solution.
2. When you use Fragment to save parameters, it may be because the parameters to be saved are large or large. In this case, the page may cause an exception. For example, code
[Java]View plaincopy
Bundle B = new Bundle ();
B. putParcelable ("bitmap", bitmap2 );
ImageRecognitionFragment. setArguments (B );
[Java]View plaincopy
Bundle B = new Bundle ();
B. putParcelable ("bitmap", bitmap2 );
ImageRecognitionFragment. setArguments (B );
After you set the parameters and add hide () and add (), you need to commit () to implement two Fragment redirects. In this case, the parameters must be saved by the system, however, at this time, you have implemented redirection, but the system parameters are not saved. At this time, it will be reported
Java. lang. IllegalStateException: Can not perform this action after onSaveInstanceState
Exception. Cause Analysis: You do not need to save the system parameters. As long as the parameters you set can be passed in and accepted in another Fragment, now, android provides another submission method in the form of commitAllowingStateLoss (). We can see from the name that this submission allows loss of status values. The problem can be solved perfectly, and the transfer of values is controlled by yourself.
Another problem is also mentioned here. bitmap can also be passed through Bundle. You can use putParacelable.
In addition:
Public final boolean isAdded ()
If the Fragment object is added to its Activity, true is returned; otherwise, false is returned.
Fragment not attached to Activity exception