Android的异步消费Web服务Android、Web

由网友(讨厌朕的人多了你算老几)分享简介:我需要一点点手拿着从C#与Java / Android的转变为客户消耗当然Web服务异步,因此它不会锁定GUI ....(进度条上会锦上添花。 )在C#中我将创建对象做这样的事情在客户端。创建一个服务引用。创建服务接口的成员,并填充相匹配的对象。启动服务请求经过物体在步骤二在一个单独的线程创建的。等到显示进度条。处理响...

我需要一点点手拿着从C#与Java / Android的转变为客户消耗当然Web服务异步,因此它不会锁定GUI ....(进度条上会锦上添花。 )在C#中我将创建对象做这样的事情在客户端。

创建一个服务引用。创建服务接口的成员,并填充相匹配的对象。启动服务请求经过物体在步骤二在一个单独的线程创建的。等到显示进度条。处理响应是否错误或返回的数据。

现在也许是我过于简单,但我在Java中认为这将是pretty接近这个方法。我所看到的是有很多人说,延长AsyncTask的类。我所缺少的是如何通过我的价值从客户端?例如如何发送的用户名和密码?恐怕所有不同的文章和细微差别混淆了我。我只是需要把工作做了直接的方式。

所以,我将不胜感激任何提示,指针,教程或其他这样的阅读。

JB

解决方案

 公共类AsyncHtt prequestManager延伸的AsyncTask<字符串,布尔值,字符串> {    私人最终字符串的serviceUrl =URL HERE;    字符串的用户;    字符串传递;    公共AsyncHtt prequestManager(字符串用户,字符串传递){        this.user =用户;        this.pass =传递;    }    @覆盖    保护字符串doInBackground(字符串... PARAMS){        //执行职务        返回;    }    保护无效onPostExecute(字符串结果){        Log.d(信息,结果);        //更新的结果的用户界面    }} 

和您使用执行调用

 新AsyncHtt prequestManager(user和pass).execute(); 
Android使用KSWEB搭建HTTP WEB服务器环境

I need a little hand holding transitioning from C# to Java / Android for a client to consume a web service async of course so it doesn't lock the gui....(a progress bar would be icing on the cake.) In C# I would create the object do something like this in the client.

Create a service reference. Create an object that matches the service interface members and populate. Launch service request passing object created in step two in a separate thread. wait showing progress bar. Handle response whether error or return data.

Now perhaps I'm being too simplistic but I assumed in Java it would be pretty close to this method. What I am seeing is alot of people saying to extend the AsyncTask class. What I am missing is how I pass my values from the client? For example how do I send the username and password? I'm afraid all the different articles and nuances are confusing me. I just need a straight forward way to get the job done.

So I would be grateful for any tips, pointer, tutorials or other such reading.

JB

解决方案

public class AsyncHttpRequestManager extends AsyncTask<String, Boolean, String> {
    private final String serviceUrl = "URL HERE";
    String user;  
    String pass;

    public AsyncHttpRequestManager(String user, String Pass){
        this.user = user;  
        this.pass = pass;
    }

    @Override
    protected String doInBackground(String... params) {
        //execute the post
        return "";
    }

    protected void onPostExecute(String result) {
        Log.d("MESSAGE", result);
        //update the UI with the results
    }
}

and you execute the call using

new AsyncHttpRequestManager(user, pass).execute();

阅读全文

相关推荐

最新文章