Java - How to Retrieve and use a single value from azure mobile services in Android

前端 未结 3 428
情深已故
情深已故 2021-01-21 02:25

I am new to azure but i know certain things like how to retrieve and store data to azure , i followed azure official documentation for this purpose.

Link is Here - https

3条回答
  •  广开言路
    2021-01-21 03:09

    I got it solved. No need to create a custom API.

    Just follow the basics , Here is the code :-

    final String[] design = new String[1];
    
    private MobileServiceTable mUser;
    
    mUser = mClient.getTable(User.class);
    
                new AsyncTask() {
                    @Override
                    protected Void doInBackground(Void... params) {
                        try {
                            final MobileServiceList 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();
    

    DON'T forget to create a class User for serialization and all. Also you should define the array .

    FEEL FREE to write if you got it not working.

    EDIT :-

    design[0] is an array with size 1.

    eq(x) is equal to x where , x variable contains username for which i want designation from database (azure).

提交回复
热议问题