Last active
April 12, 2016 20:08
-
-
Save naiduv/967168e3b42e77d7d6944049b32aff1c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //as you have already seen in azure portal, there is a snippet that they provide in order to post items from the app to the mobile service. | |
| //its pretty close to what is needed, but it DOES NOT WORK | |
| //after much searching, the following code is an alternative that I have found to work. | |
| public class SomeActivity { | |
| private MobileServiceClient mClient; | |
| private MobileServiceTable<ToDoItem> mToDoTable; | |
| //THIS IS WHAT NEEDS TO CHANGE!! MAKE SURE IT LOOKS LIKE THIS | |
| public class Item { | |
| @com.google.gson.annotations.SerializedName("Complete") | |
| public boolean Complete; | |
| @com.google.gson.annotations.SerializedName("Text") | |
| public String Text; | |
| @com.google.gson.annotations.SerializedName("Id") | |
| public String Id; | |
| } | |
| //call this in the oncreate of your activity | |
| public void Init(){ | |
| mClient = new MobileServiceClient( | |
| "https://myapp.azure-mobile.net/", | |
| "app-key-that-azure-gave-me", | |
| this); | |
| // Get the Mobile Service Table instance to use | |
| mToDoTable = mClient.getTable(ToDoItem.class); | |
| } | |
| //change the insert to look like this | |
| public void InsertItems(){ | |
| Item item = new Item(); | |
| item.Text = "Awesome item"; | |
| try { | |
| //the insert provided in the azure example does not work and the function used is deprecated | |
| mToDoTable.insert(item); | |
| } catch(Exception ex) { | |
| Log.d("TESTLOG", "Failed because: "+ ex.getMessage()); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment