Reprint: http://blog.csdn.net/winson_jason/article/details/20357435
The following two problems, is encountered in the development of some of the occasional problem of fragment, today more time, on the Internet search Some solutions: 1, about fragment (xxfragment) not attached to Activity exception. This exception occurs because a function that requires context content, such as GetResource (), is called when fragment is not attach to the activity. The workaround is to wait for the code that is called to be written in OnStart (). There are a few other references on the Web: Http://stackoverflow.com/questions/10919240/fragment-myfragment-not-attached-to-activity's main answer is to call
Getresources (). getString (R.string.app_name); Getresources (). getString (R.string.app_name);
Before adding a Judge isadded (), two outside said that this unusual solution has http://stackoverflow.com/questions/6870325/ Android-compatibility-package-fragment-not-attached-to-activity
This is a workaround for another scenario.
2, when using fragment to save parameters, it may be because you need to save the parameter is larger or more, in this case the page will cause an exception. such as code
Bundle B = new bundle (); B.putparcelable ("Bitmap", BITMAP2); Imagerecognitionfragment.setarguments (b);
Set the parameters, and added hide (), add (), after the method, need to commit (), to implement the two fragment jump, in this case the parameters need to be saved in the system, but this time you have implemented the jump, the system parameters are not saved. It will be reported at this time
Java.lang.IllegalStateException:Can not perform this action after onsaveinstancestate
Abnormal. Analysis Reason: You do not need to save the parameters of the system, as long as you set the parameters can pass the past, in another fragment can be successfully accepted on the line, now Android provides another form of submission Commitallowingstateloss (), As you can see from the name, this commit is allowed to lose the status value. To get this problem solved perfectly, the value of the transfer is your own control. Here's another question, bitmap can also be passed through bundles, using putparacelable.
[Android Pro]