Fragment construction problems, display text formatting problems in Android, determine which class is jumping into the current class problem

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.