Xiao Kee 1. About the initialization of fragment
When we set up the interface using the avtivity+fragment combination, we usually have new fragment in the activity, but when we need to pass the parameters in fragment, Are we going to have a problem with the way we use the constructor in the fragment? Yes, we are using the method of construction in the Androidstudio parameter, will be error, simply said: "Fragment in the way the parameter assignment can cause a memory leak problem", the code is as follows:
Public myfragment (Context mcontext,list<string> list) { this.list = list; This.mcontext = Mcontext;}
This piece of code will be myfragment under the red, why? That is, if the parameters are assigned in this way, the values may still exist when fragment is destroyed, causing a memory leak. Why? I don't know, my boss told me. What if you want to send a parameter assignment? You can use the following code instead
Public myfragment () {} Public Static Myfragment getinstance (Context mcontext,list<string> List) { new Fragment (); New Bundle (); Argument.putserializable ("CONTEXT", mcontext); Argument.putserializable ("list", list); Fragment.setargument (argument); return fragment;}
After the external take out the desired value assignment, so that the problem of error solved;
Not to be continued ...
2. String.Format () 3. IsAssignableFrom (class Class)
Fragment construction problems, display text formatting problems in Android, determine which class is jumping into the current class problem