Using Set operator in content resolver Android - android

I have to update a Content Provider DB. As per requirement, I only can do that using context.getContentResolver().
Bt I am unable to use SET operator in this method. Can someone help me on this.
Thanks in advance.

Basically you need to create new URI and implement it's raw query in a way to incorporate join condition between the tables.
This SO answer explains in pretty decent way..Have a look!

Related

How can I filter and sort my documents in Firestore RecylerView (Firestore UI)?

I want to sort and filter my documents like the below code. But it didn't work. Actually, when I add a new document I can't see it in real-time.
val query: Query = FirebaseFirestore.getInstance()
.collection("Lessons")
.whereEqualTo("tag",tag)
.orderBy("order",Query.Direction.ASCENDING)
val options: FirestoreRecyclerOptions<Model> = FirestoreRecyclerOptions.Builder<Model>()
.setQuery(query, Model::class.java)
.build()
adapter = KonuRecyclerAdapter(options,tag,konuBasligi)
binding?.konularAnaRecyclerView?.adapter = adapter
But when I comment "whereEqualto" line I can see new documents (Newly added). After that, if I uncomment this line again, I can see this document too. I want that when I add a new document it will show in real-time. Please help me with this problem. You can warn me of any mistakes that I did. Any help will be appreciated!!!
As far as I can tell you are trying to use a Query that contains a call to:
.whereEqualTo("tag",tag)
And
.orderBy("order",Query.Direction.ASCENDING)
On a different field. This kind of query requires an index. To see how you can solve this, please see my answer from the following post:
Firestore whereEqualTo, orderBy and limit(1) not working
However, using a call to .whereEqualTo() without an ordering or, a call to .orderBy() without a .whereEqualTo() call, doesn't require an index. That's the reason why it's working when you comment one, or the other method calls.

ContentProvider project as library for other projects

I had read the documentation of ContentProvider and quite good number of tutorials\questions but seems there's gap in my head about how could I use the ContentProvider project; the first project which is the ContentProvider from TutorialPoint and it's working fine, I added to my demo project the following statement android:sharedUserId="com.example.mycontentprovider to my AndroidManifest.XML to access the shared DB I had there. Now I want to use the CRUD functions and I'm not sure how to do this, I found one of solutions here is to do such statement Context friendContext = this.createPackageContext("com.example.mycontentprovider",Context.CONTEXT_IGNORE_SECURITY);
Another solution been found is to initialize Intent and start activity and I did as the following:
Intent openMyContentProvider = new Intent("com.example.mycontentprovider",MainActivity.this);
and it gives me error for the arguments and though not sure how to proceed after starting new Activity; Any further requirements or codes will be provided and thanks in advance for your response.
You can use a CursorLoader to read data from the content provider, with the advantage of getting updates when the data in the database changes.
Use ContentResolver for read, insert, update and delete operations. And there is AsyncQueryHandler to help make handling asynchronous ContentResolver queries easier, you can use its on*Complete() callbacks to let the user know the operation was successful. Using AsyncQueryHandler

Utterly confused about loading SQLite data in Honeycomb (Android)

I am new to android development and I've hit a hurdle when trying to load SQLite data to populate a ListFragment. In previous versions of android one made a new instance of the cursor class, made an SQLite query to place the cursor in the appropriate position, called startManagingCursor, made a new SimpleCursorAdapter and finally called setListAdapter. Pretty darn simple (too bad about the UI thread)!
Now almost all of these methods are deprecated and I have no idea how to populate my poor ListView. The documentation says I should use CursorLoader but here on StackOverflow people advise against using it for SQLite queries. How do I tell my cursor to populate the ListView?
Thanks a lot in advance!
You need to convert you DbAdapter into a Content Provider if you want to use CursorLoaders. and put android:exported= false as a property of your content provider so that it is private. Android team is favoring this approach as they say Content Provider is better suited to handle logic. That is why they are bent on deprecating our old ways( was hard on me too). But I have changed my dbadapters to content providers and now gleefully using cursor loaders( they are too cool not to be used). Try it, generally you will do fine with some more boilerplate code of Content Providers in adition to that of DBadapter and sqliteHelper. GO for it!

How to refer to an array by Uri in Android?

Programming my application would be a lot easier if I could refer to an array by URI, and use that array to inflate a list. Has anyone done this? Thanks in advance!
No, it's not possible to refer to an array using a Uri in the same way that you do using R.array.yourarray.
Technically, just to say the proper answer, you could wrap an object to parse the Uri for you and return the R.array.yourarray for you. Like a Content Provider, for example. But obviously that is just nonsense, there is no reason to create a non standard thing when the standard works just fine.
I don't think there is any scenario that would require a Uri that the standard way doesn't handle just fine.

android how to compare between simpleCursorAdapter and ArrayAdapter

I have an application. I want to optimize that one. how can i do that.
For example I am using simpleCursorAdapter to bind listview and it fetch data from database.
But if i retrieve data from cursor into an string array and then by using ArrayAdapter I can bind listview.
So I want to know which one is the better one means which takes less time to binding or takes less CPU time.
Plz give me the answer.
And if u have any extra tips of code optimization then tell me plz.
Thank you
Please try to test by your self. Have a look on the following steps to check performance difference
Create a sample application where you write both of the technique. also print two print statements for displaying and free heap memory
one statement before calling database
second statement after creation of list view
In this way you can find which technique is better as per your requirement.
Thanks
Deepak

Categories

Resources