About sharedpreferences writing and deleting array data

Source: Internet
Author: User

Because of the number of values, individual storage and deletion is not enough, so write a simple array-format write and delete operations.

/*** used to store the corresponding string type *@paramContext Contextual Object *@paramkey array of keys stored *@paramvalues stored in the value array*/         Public Static voidPutstringarray (Context context,string[] key,string[] values) { for(inti = 0; i < key.length; i++) {                if(sharedpreferences==NULL) {sharedpreferences=context.getsharedpreferences ("config", context.mode_private);            } sharedpreferences.edit (). putstring (Key[i], values[i]). commit (); }        }        /*** used to store the corresponding bool type *@paramContext Contextual Object *@paramkey array of keys stored *@paramvalues stored in the value array*/         Public Static voidPutboolarray (Context context,string[] key,boolean[] values) { for(inti = 0; i < key.length; i++) {                if(sharedpreferences==NULL) {sharedpreferences=context.getsharedpreferences ("config", context.mode_private);            } sharedpreferences.edit (). Putboolean (Key[i], values[i]). commit (); }        }                    /*** Removes the specified node from the SP (removed by array) *@paramContext Environment *@paramkey requires removing the name of the node*/         Public Static voidRemovearray (context context, string[] key) { for(inti = 0; i < key.length; i++) {                if(sharedpreferences==NULL) {sharedpreferences= context.getsharedpreferences ("config", context.mode_private);            } sharedpreferences.edit (). Remove (Key[i]). commit (); }                    }

  

About sharedpreferences writing and deleting array data

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.