Custom cursor contentprovider

Source: Internet
Author: User

Applications must interact with other colleagues' applications to transmit data.
My application mainly parses the packets sent from the server. It is quite simple, similar to newsrob'sProgramColleagues need the weather data,
Display the weather information. It is very easy to share data in Android, and the information stored by my program is in the database, as long as I write a contentprovide to provide data for it
Yes, but the problem comes again: The weather field in the weather report is an integer,
I only converted it into the required information when it is displayed, such as "Qing" and "Cloudy". I placed the corresponding information in string-array, when used, use the weather directly
The data in the array corresponding to the type can be retrieved, but the resource cannot be transferred between two applications.

Although he can obtain the data in a special way, I always think this is not a good way.

Its
Another colleague of mine has a good idea,
That is, to locally convert strinng-array into a custom cursor, provided by contentprovider, she had previously thought about using this method to transmit data,
However, it was not successful. Therefore, a compromise was adopted, that is, the content of strinng-array was put in the database, and then passed contentprovicer.

At that time, I also thought that "locally converting strinng-array into a custom cursor can be provided through contentprovider", but I don't know how to put data in cursor. search and find a solution on the Internet.

////
@ Override

////
Public cursor query (URI Uri, string [] projection, string selection,

////////////
String [] selectionargs, string sort ){

////////
Final int match = surlmatcher. Match (URI );

////////
Switch (MATCH ){

////////
Case demo_strings:

////////////
String [] Columns = new string [] {"_ id", "_ value "};

////////////
Matrixcursor stringcursor = new matrixcursor (columns );

////////////
Charsequence items [] = getcontext (). getresources (). getstringarray (

////////////////////
R. array. items );

////////////
String row [] = new string [2];

////////////
Int I = 0;

////////////
For (charsequence Cs: items ){

////////////////
Row [0] = "" + (++ I );

////////////////
Row [1] = cs. tostring ();

////////////////
Stringcursor. addrow (ROW );

////////////
}

////////////
Return stringcursor;

////////
Default:

////////////
Throw new illegalstateexception ("Unrecognized URI:" + URI );

////////
}

////
}

}

 

I try to cache stringcursor locally, which will lose the benefits of localization, and I don't know what the consequences of using the same cursor between multiple applications will be.

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.