Search code examples
androidandroid-contentprovider

use of BaseColumns or not with ContentProvider?


what is the difference between using BaseColumns or not with a ContentProvider? It's an interface, so it might be used somewhere else...? I don't really get the point, i'm using simple constants in my Content Provider to define the _id or the name in my database, and it works just fine. So, am i missing something?

public static final class Notes implements BaseColumns { ...

thanks

ps: i've checked this answer : What is the use of BaseColumns in Android but i can't really see the point with the answers posted


Solution

  • The point of implementing BaseColumns is the same as the point of reusing any code whatsoever; you don't have to reuse code, you can re-implement it again, the question is: what for?

    Now, in the case of BaseColumns this does not stand out so much because, obviously, all they provide is a constant for two columns (_ID and _COUNT), so you don't save that much time implementing BaseColumns instead of just adding these two constants yourself. But why not use it if you can?

    tl;dr: You don't have to use BaseColumns if you don't want to, all it does is save you from typing a few lines of code. On the other hand: since it does save you from typing them, why not use it?