The external package of Android Greendao is not very friendly.

Source: Internet
Author: User

Https://github.com/greenrobot/greenDAO

An example of downloading the Xia Guan Network is a complete package version, but self-encapsulation is a problem.

Many of the methods in Greendao's master and session are completely hidden and belong to this class only.

A lot of information is also hidden.

Can only be implemented on the basis of inheriting these two classes (like the official website example)

To achieve the most basic of a demo through the public method also encountered a lot of pits.

This is an example

     Master.devopenhelper dbhelp=New master.devopenhelper (This, "dbname",null);        Sqlitedatabase db=dbhelp.getwritabledatabase ();        Daoconfig DC=new daoconfig (Db,baiduuserdao.  Class);        Baiduuserdao DAO=new  Baiduuserdao (DC);        Baiduuser Baiduuser=new baiduuser (null, "tel", "name1", "pwd", "Mail");        Dao.insert (baiduuser);

There are two pits

One:

Baiduuserdao class must set tablename static property
public static final String TABLENAME = "Baiduuser";
Or you'll get an error.
Java.lang.NoSuchFieldException:TABLENAME

Two must be set properties static inner class
public static class Properties {
Public final static Property Id = new Property (0, Long.class, "Id", True, "_id");
Public final static Property Tel = new Property (1, String.class, "Telphone", False, "tel");
Public final static Property UserName = new Property (2, String.class, "UserName", False, "UserName");
Public final static Property e-mail = new Property (3, String.class, "password", false, "email");
Public final static Property PassWord = new Property (4, String.class, "email", False, "PassWord");
};
Or you'll get an error.
Java.lang.classnotfoundexception:com.mac.cdp.androidbaidusign.dao.baiduuserdao$properties

Fortunately, there is an abnormal information hint, otherwise there is no restrictions within the class, there is no obvious explanation.
But it can also be understood that it is too wasteful to restrict to constructs, while static methods are more field-saving.

......

I still follow the example of Git in the test code, by inheriting the session and master.

I really don't have to worry about anything.

Want to not according to the path of the official website to encapsulate a few tool classes, found that there is no way to go, only according to his path


Master 's Registerdaoclass method
Can only be called in a subclass. The public method is not provided and can only be called in a subclass implementation, or a layer of public methods.


The external package of Android Greendao is not very friendly.

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.