Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/200.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Android服务中验证Azure移动服务_Android_Azure Mobile Services - Fatal编程技术网

如何在Android服务中验证Azure移动服务

如何在Android服务中验证Azure移动服务,android,azure-mobile-services,Android,Azure Mobile Services,我按照指示做了一个小时,效果很好 但我想在服务中进行身份验证。这不起作用,因为它需要在对话框中显示WebView,即使我已经通过身份验证,对话框将消失 这是堆栈跟踪,我的服务被替换为*** 08-03 18:19:56.824 12259-12259/org.l6n.hn E/AndroidRuntime﹕ FATAL EXCEPTION: main Process: org.l6n.hn, PID: 12259 java.lang.RuntimeException: Unab

我按照指示做了一个小时,效果很好

但我想在服务中进行身份验证。这不起作用,因为它需要在对话框中显示WebView,即使我已经通过身份验证,对话框将消失

这是堆栈跟踪,我的服务被替换为
***

08-03 18:19:56.824  12259-12259/org.l6n.hn E/AndroidRuntime﹕ FATAL EXCEPTION: main
    Process: org.l6n.hn, PID: 12259
    java.lang.RuntimeException: Unable to create service ***: java.lang.ClassCastException: *** cannot be cast to android.app.Activity
            at android.app.ActivityThread.handleCreateService(ActivityThread.java:2595)
            at android.app.ActivityThread.access$1800(ActivityThread.java:139)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1292)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5086)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: java.lang.ClassCastException: *** cannot be cast to android.app.Activity
            at com.microsoft.windowsazure.mobileservices.LoginManager.showLoginUI(LoginManager.java:282)
            at com.microsoft.windowsazure.mobileservices.LoginManager.authenticate(LoginManager.java:143)
            at com.microsoft.windowsazure.mobileservices.MobileServiceClient.login(MobileServiceClient.java:230)
            at com.microsoft.windowsazure.mobileservices.MobileServiceClient.login(MobileServiceClient.java:214)
            at ***.authenticate(***.java:118)
            at ***.onCreate(***.java:47)
            at android.app.ActivityThread.handleCreateService(ActivityThread.java:2585)
            at android.app.ActivityThread.access$1800(ActivityThread.java:139)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1292)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5086)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
            at dalvik.system.NativeStart.main(Native Method)

如果您的用户已经通过身份验证,则无需再次调用login方法(这正是试图显示对话框的内容)。如果MobileServiceClient.getCurrentUser()方法返回有效的用户,您可以在后台服务中调用。如果此时没有有效用户,则必须在UI线程上显示该对话框(即不在后台服务中),或者可以对移动服务进行未经验证的呼叫。因此,在小时后台服务中,您可能需要这样的服务:

if (myMobileServiceClient.getCurrentUser() != null && myMobileServiceClient.getCurrentUser().getUserId() != "") {
    //do your background service calls to your Mobile Service
} else {
    //Fire something back to the UI thread to prompt a login and restart service
}

另一方面,您可能可以序列化MobileServiceUser实例并将其存储在公共位置,然后使用“身份验证”您的客户端,而无需基于UI的登录。