Java - 如何从 Android 中的 azure 移动服务检索和使用单个值

标签 java android azure azure-mobile-services

我是 azure 新手,但我知道某些事情,例如如何检索数据并将数据存储到 azure,为此我遵循了 azure 官方文档。

链接在这里 - https://azure.microsoft.com/en-in/documentation/articles/mobile-services-android-get-started-data/

但问题是,本教程仅展示如何使用适配器和列表从 azure 检索和使用数据。 我想知道,如何从 azure 移动服务检索单个值以及如何在 android 中使用它

请为我提供后端代码(如果有的话)和java代码。提前致谢

最佳答案

我已经解决了。无需创建自定义 API。

只需遵循基础知识即可,这是代码:-

final String[] design = new String[1];

private MobileServiceTable<User> mUser;

mUser = mClient.getTable(User.class);

            new AsyncTask<Void, Void, Void>() {
                @Override
                protected Void doInBackground(Void... params) {
                    try {
                        final MobileServiceList<User> result =
                                mUser.where().field("name").eq(x).execute().get();
                        for (User item : result) {
                           // Log.i(TAG, "Read object with ID " + item.id);
                            desig[0] = item.getDesignation(); //getDesignation() is a function in User class ie- they are getters and setters
                            Log.v("FINALLY DESIGNATION IS", desig[0]);

                        }

                    } catch (Exception exception) {
                       exception.printStackTrace();
                    }
                    return null;
                }

                @Override
                protected void onPostExecute(Void aVoid) {
                    super.onPostExecute(aVoid);
                    designation.setText(desig[0]);
                }
            }.execute();

不要忘记为序列化等创建一个User类。您还应该定义数组。

如果您发现它不起作用,请随意写

编辑:-

design[0] 是一个大小为 1 的数组。

eq(x) 等于 x,其中,x 变量包含我想要从数据库 (azure) 指定的用户名。

关于Java - 如何从 Android 中的 azure 移动服务检索和使用单个值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31364134/

相关文章:

Java : Getting NullPointerException while parsing the List and setting it inside a Array

java - 如何在 Java 中将 UNIX 时间戳转换为 XMLGregorianCalendar 值?

android - 从堆栈中清除启动器 Activity

javascript - Codeigniter 的 URL 问题(Azure AD 回复 URI)

java - HDFS 缓冲写/读操作

java - 如何将 web-socket 映射到 url 模式?

java - 如何在 fragment 而不是 Activity 中使用 NavController(在 fragment 中带有 NavHost)?

android - 支持 C++11 的最低 Android 操作系统版本

c# - 将 WCF 服务发布到 Azure 而不向源代码管理添加代码?

node.js - 如何删除Azure NodeJS的blob存储容器