获取移动服务客户端作为全局变量,并将来自Android中另一个类的数据存储在Azure中
我已经使用azure进行了身份验证,为此,我在一个活动中使用了移动服务客户端,下一个活动必须添加一些数据,因此我需要移动服务客户端在azure DB中存储数据。我该怎么做?请给我提供一些解决方案 以下是在以下登录活动中使用移动服务客户端进行身份验证的代码:获取移动服务客户端作为全局变量,并将来自Android中另一个类的数据存储在Azure中,android,azure,Android,Azure,我已经使用azure进行了身份验证,为此,我在一个活动中使用了移动服务客户端,下一个活动必须添加一些数据,因此我需要移动服务客户端在azure DB中存储数据。我该怎么做?请给我提供一些解决方案 以下是在以下登录活动中使用移动服务客户端进行身份验证的代码: public static MobileServiceClient mClient; public MobileServiceTable<User> mUser; public static MobileServiceTabl
public static MobileServiceClient mClient;
public MobileServiceTable<User> mUser;
public static MobileServiceTable<Location> mLocation;
try {
// Create the client instance, using the provided mobile app URL.
mClient = new MobileServiceClient(url, this);
mClient.setAndroidHttpClientFactory(new OkHttpClientFactory() {
@Override
public OkHttpClient createOkHttpClient() {
OkHttpClient client = new OkHttpClient();
client.setReadTimeout(20, TimeUnit.SECONDS);
client.setWriteTimeout(40, TimeUnit.SECONDS);
return client;
}
});
//connecting the azure user table dbo.users
mUser = mClient.getTable("User", User.class);
mLocation = mClient.getTable("Location", Location.class);
现在,我需要使用上述mclient为用户存储Azure中的位置。根据您的描述 要在Azure中存储数据,我们可以执行以下操作:
public Location addLocation(MobileServiceTable<Location> table, Location location){
return table.insert(location).get();
}
将此类的全名设置为应用程序的name属性,如下所示:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
MyApplication myApplication= (MyApplication) this.getApplication();
mClient = myApplication.getMobileServiceClient();
然后我们可以在以下不同的活动中使用它:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
MyApplication myApplication= (MyApplication) this.getApplication();
mClient = myApplication.getMobileServiceClient();
因此,我还想问我何时从azure添加身份验证,每次调用api时azure都会询问身份验证。你能解释一下我是否必须从另一个类更新表数据。因为像这样使用McClient无助于我将数据发送到azure DB。@你的意思是想在一个活动和中获取位置吗您需要使用此位置的其他活动?如果问题已解决,您可以将有用的帖子标记为答案,以帮助其他社区成员快速找到有用的信息。
package cn.azurepro.test.global;
import android.app.Application;
import com.microsoft.windowsazure.mobileservices.MobileServiceClient;
public class MyApplication extends Application {
private MobileServiceClient mobileServiceClient=null;
public void setMobileServiceClient(MobileServiceClient mobileServiceClient){
this.mobileServiceClient=mobileServiceClient;
}
public MobileServiceClient getMobileServiceClient(){
return mobileServiceClient;
}
@Override
public void onCreate() {
super.onCreate();
}
}
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
MyApplication myApplication= (MyApplication) this.getApplication();
mClient = myApplication.getMobileServiceClient();