Bmob Development Guide "Android Side"

Source: Internet
Author: User

As a developer, data storage, user login, verification and other operations, is essential to the program, the following we will start from the basic information bmob:

"Bmob"

Official website: http://www.bmob.cn/

Help document:Http://www.bmob.cn/site/getdocs

Basic operation:http://docs.bmob.cn/android/faststart/index.html?menukey=fast_start&key=start_android

SDK Download: http://www.bmob.cn/site/sdk

basic user Action "

Ⅰ User registration:

There are two types of tables registered by the user, one inheriting Bmobuser, one inheriting bmobobject, but most of them used as the user's registration bmobuser

JavaBean Code:

public class Students extends Bmobuser {    private int age;    Private String address;    Public String getaddress () {        return address;    }    public void setaddress (String address) {        this.address = address;    }    public int getage () {        return age;    }    public void Setage (int.) {        this.age = age;    }}

Implementation method:

private void Showregist () {        //user-registered method        String username=edt_user.gettext (). toString ();        String Password=edt_password.gettext (). toString ();        Students stu=new Students ();        Stu.setusername (UserName); Username and password as the user table in Bmob, this table field already exists, so it is not possible to create        Stu.setpassword (password) in JavaBean;        Stu.setage (+);        Stu.setemail ("[email protected]"); Test use, the function of the mailbox verification        stu.setaddress ("Binzhou");         /* * User Registration Submission         *        /Stu.signup (mainactivity.this,new Savelistener () {            @Override public            Void Onsuccess () {                toast.maketext (mainactivity.this, "registered successfully", Toast.length_short). Show ();            @Override public            void onfailure (int i, String s) {                toast.maketext (Mainactivity.this, "failed to register" +s,toast.length_ Short). Show ();            }        });    

Background database:

Ⅱ User login:

private void Showsubmit () {//user logon method String Username=edt_user.gettext (        ). ToString ();       String Password=edt_password.gettext (). toString (); Final Bmobuser user=new bmobuser ();//Create the object, which is a match for the Bmob created class//with the information in the database, successfully returned successfully, failed to return information User.setusername (UserN        AME);        User.setpassword (password); /* User Login */user.login (mainactivity.this,new Savelistener () {@Override publi c void Onsuccess () {if (user.getemailverified ()) {Toast.maketext (mainact                Ivity.this, "Login Successful", Toast.length_short). Show (); }else{//Mailbox Not verified}} @Override public void onfailure (int            I, String s) {Toast.maketext (mainactivity.this, "Login Failed" +s,toast.length_short). Show ();    }        }); }}

Ⅲ Updating user data

private void Showupdate () {        //user-Updated method        Students stu=bmobuser.getcurrentuser (Mainactivity.this, Students.class);        Stu.setaddress ("Linyi");        Stu.setage (+);        Stu.update (Mainactivity.this, "5c8095e99b", new Updatelistener () {            @Override public            void onsuccess () {                Toast.maketext (mainactivity.this, "Update succeeded", Toast.length_short). Show ();            @Override public            void onfailure (int i, String s) {                toast.maketext (mainactivity.this, "Update failed" +s,toast.length_ Short). Show ();            }        });    

Ⅳ Change Password

private void Showrepassword () {    //Change Password method    final String email= "[email protected]";    Bmobuser.resetpassword (mainactivity.this,email,new Resetpasswordlistener () {        @Override public        Void Onsuccess () {            toast.maketext (mainactivity.this, "Change password, go to" +email,toast.length_short). Show ();        @Override public        void onfailure (int i, String s) {            toast.maketext (Mainactivity.this, "Failed to reset password", toast.length_ Short). Show ();        }    });

PS: the system will default to the mailbox you entered to send a change password to the message
--------------------------------------------------------------------------------------------------------------- --------------------

"Picture Action"

Ⅴ Uploading Images

private void Submit () {//upload picture String path= "sdcard/download/shareone.jp        G "; Final Bmobfile file=new bmobfile (new file); Create Bmobfile object, convert to Bmob object File.upload (mainactivity.this,new Uploadfilelistener () {@Override P                ublic void onsuccess () {Share share=new share ();                Share.setname ("Shareone");                Share.setage (20);  Share.seticon (file); Set Picture Share.save (Mainactivity.this,new Savelistener () {@Override PU                    Blic void onsuccess () {Toast.maketext (mainactivity.this, "Upload succeeded", Toast.length_long). Show ();                        } @Override public void onfailure (int i, String s) {                    Toast.maketext (Mainactivity.this, "Upload failed" +s,toast.length_long). Show ();            }                }); }

JavaBean class:

public class Share extends Bmobobject {    private String name;    private int age;    Private bmobfile icon;    Public String GetName () {        return name;    }    public void SetName (String name) {        this.name = name;    }    public int getage () {        return age;    }    public void Setage (int.) {        this.age = age;    }    Public Bmobfile GetIcon () {        return icon;    }    public void SetIcon (bmobfile icon) {        This.icon = icon;    }}

Background display:

Ⅵ Download Image

private void Download () {        //download picture        bmobquery<share> query=new bmobquery<share> ();        Query.getobject (Mainactivity.this, "f4514dcb9d", new Getlistener<share> () {            @Override public            Void Onsuccess (Share share) {                bmobfile icon=share.geticon ();                Icon.loadimage (mainactivity.this,image);            }            @Override public            void onfailure (int i, String s) {            }        });    

Ⅶ Loading picture thumbnails

private void Load () {        //load thumbnail        bmobquery<share> query_load=new bmobquery<share> ();        Query_load.getobject (Mainactivity.this, "f4514dcb9d", new Getlistener<share> () {            @Override            public void onsuccess (Share share) {                bmobfile icon=share.geticon ();                Icon.loadimagethumbnail (mainactivity.this,load_show,100,100);            }            @Override public            void onfailure (int i, String s) {            }        });    

-------------------------------------------------------------------------------------------------------

"Data Manipulation"

JavaBean class:

Public class footballer extends Bmobobject {    private String name;    private int age;    private  int score;    Public String GetName () {        return name;    }    public void SetName (String name) {        this.name = name;    }    public int getage () {        return age;    }    public void Setage (int.) {        this.age = age;    }    public int Getscore () {        return score;    }    public void SetScore (int score) {        this.score = score;    }}

Ⅷ Add Data

private void Showcreate () {        footballer fb=new footballer ();        Fb.setname ("Monster");        Fb.setage (a);        Fb.setscore (+);        Fb.save (mainactivity.this,new Savelistener () {            @Override public            void onsuccess () {                Toast.maketext ( Mainactivity.this, "created successfully", Toast.length_short). Show ();            @Override public            void onfailure (int i, String s) {                toast.maketext (Mainactivity.this, "failed to create" +s,toast.length_ Short). Show ();            }        });    

Ⅸ Updating data

private void Update () {        footballer fb=new footballer ();        Fb.setname ("Monsterlin");        Fb.setscore (+);        Fb.setage (+);        Fb.update (Mainactivity.this, "Ed8f8bdd14", new Updatelistener () {            @Override public            void onsuccess () {                Toast.maketext (mainactivity.this, "Update succeeded", Toast.length_short). Show ();            @Override public            void onfailure (int i, String s) {                toast.maketext (mainactivity.this, "Create failed" + S, toast.length_ Short). Show ();            }        });    

Ⅹ Deleting data

private void Delete () {        footballer fb=new footballer ();        Fb.setobjectid ("7a01c65384"); Delete the corresponding Objectid        fb.delete (mainactivity.this,new deletelistener () {            @Override public            void onsuccess () {                Toast.maketext (mainactivity.this, "delete succeeded", Toast.length_short). Show ();            @Override public            void onfailure (int i, String s) {                toast.maketext (mainactivity.this, "Delete failed", Toast.length_ Short). Show ();            }        });    

Ⅺ Querying data

private void Query () {        bmobquery<footballer> query=new bmobquery<footballer> ();        Query.addwhereequalto ("name", "Monster");        Query.findobjects (mainactivity.this,new findlistener<footballer> () {            @Override public            void onsuccess (List<footballer> footballers) {                for (footballer Fb:footballers)                {                    toast.maketext (mainactivity.this, "query data Succeeded" +fb.getname () + "---" + Fb.getscore (), Toast.length_short). Show ();                }            }            @Override public            void OnError (int i, String s) {                toast.maketext (mainactivity.this, "Query Failed" +s, Toast.length_ Short). Show ();            }        });    

"Mailbox Verification"

Email verification Reference "User Registration" section, email verification needs to open the Mailbox verification service under your corresponding Bmob

------------------------------------------------------------------------------------------------------

"A little something to say"

1.bmob 's initialization recommendations:

public class Baseactivity extends Activity {    @Override    protected void onCreate (Bundle savedinstancestate) {        //TODO auto-generated method Stub        super.oncreate (Savedinstancestate);                Initialize BMOBSDK        bmob.initialize (This, "Application ID");

then the written class inherits baseactivity

bmobuser with bmobobject bmobuser bmobobject

3. The use of Bmob requires the loading of the SDK as well as the configuration manifest file, specific actions: http://docs.bmob.cn/android/faststart/index.html?menukey=fast_start&key=start_android#index_%E5%AE%89% E8%A3%85BMOBSDK

4. Follow-up continues with new ...

Bmob Development Guide "Android Side"

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.