Windows Azure Mobile Service

Source: Internet
Author: User
Tags windows azure sdk azure sdk

I built an Android app and Windows Azure Mobile service mates to realize the function of membership registration, the actual is very simple, the Microsoft home Things really good

Start with a new mobile Service

New->mobile service->create Pop-up dialog box

URL to customize a, if someone registered will error, change a good, database new or use already existing can, after the new will let you enter the new database name and password, backend to choose JavaScript, click the arrow next

Using the existing will let you enter the password, set up to complete, click on the main interface to the left of the mobile service, appears

I choose "Connect an existing Android app" here, but now the following Microsoft tutorial is put there

Make sure Build.gradle (project: Your own project name) is in your Android app:

repositories {        jcenter ()    }

Adding the Windows Azure SDK to Build.gradle (Project:Model:app) is to add these words to the dependencies:

Compile ' com.google.code.gson:gson:2.3    '    com.google.guava:guava:18.0 '     com.microsoft.azure:azure-mobile-services-android-sdk:2.0.3 ' com.microsoft.azure ', Name: ' Azure-notifications-handler ', version: ' 1.0.1 ', ext: ' jar ')

Add in your own implementation Mobileservice function code:

Private Mobileserviceclient mclient;
Private ProgressBar Mprogressbar;
Try {            mclient=new mobileserviceclient ("Your url"                    ,"Your Key",                    this ). Withfilter (new  progressfilter ());            Mstudenttable=mclient.gettable (Student.  Class);         Catch (malformedurlexception e) {            e.printstacktrace ();            Createandshowdialog (new Exception ("Mobile service error, check URL and key"), "error");        
Private classProgressfilterImplementsServicefilter {@Override PublicListenablefuture<servicefilterresponse>HandleRequest (servicefilterrequest request, Nextservicefiltercallback next) {Runonuithrea D (NewRunnable () {@Override Public voidrun () {if(Mprogressbar! =NULL) mprogressbar.setvisibility (progressbar.visible);            }            }); Settablefuture<ServiceFilterResponse> result =settablefuture.create (); Try{servicefilterresponse response=Next.onnext (Request). get ();            Result.set (response); } Catch(Exception exc) {result.setexception (exc);            } dismissprogressbar (); returnresult; }    }
Private void Dismissprogressbar () {        runonuithread(new  Runnable () {            @Override            public  void  run () {                ifnull) mprogressbar.setvisibility ( Progressbar.gone);             }        });    }

The "Your URL" and "Your Key" in the above code are replaced with your own new mobile service URL and key, in fact, in the wizard now, there is no click on the "DASHBOARD" above, your URL and key

For key, click Manage KEYS, wait a second, and copy the Application key.

Next, define the entity class to be transferred student

ImportCom.google.gson.annotations.SerializedName;Importjava.util.Objects;/*** Created by Chen on 2015/9/19.*/ Public classStudent {@SerializedName ("id")    PrivateString MID; @SerializedName ("Stuid")    PrivateString Mstuid; @SerializedName ("Name")    PrivateString Mname; @SerializedName ("Sex")    PrivateString Msex; @SerializedName ("QQ")    PrivateString mqq; //Constructor     PublicStudent () {} PublicStudent (String id,string stuid,string name,string sex) { This. SetID (ID);  This. Setstuid (Stuid);  This. SetName (name);  This. Setsex (Sex); }     Public voidSetID (String id) { This. MID =ID; }     Public voidsetName (String name) { This. mname=name; }     Public voidsetsex (String sex) { This. Msex =sex; }     Public voidSetstuid (String stuid) { This. Mstuid =Stuid; }     Public voidSETSTUQQ (String stuqq) { This. mqq=Stuqq;} @Override PublicString toString () {returngetName ();}  PublicString GetName () {returnMname;}  PublicString GetID () {returnMID;}  PublicString Getstuid () {returnMname;}  PublicString Getsex () {returnmsex;}}

Note: the "id" in the entity class similar to @serializedname ("id") is consistent with the column name defined in Azure management, as long as the consistent mobile service resolves the JSON itself and stores it in the database.

The following is the definition of the database, in the Azure management interface, point data, select its own database, create a new table, the table column to be consistent with the entity class above, the final effect should be this

Running the Android client, success!

Windows Azure Mobile Service

Related Article

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.