Android Asyntask,第二个参数是在第一个之前发送信息

时间:2017-06-09 13:01:36

标签: android soap android-asynctask

在从“layer_2”接收信息之前,我需要使用SOAP请求从“layer_1”获取Async方法的信息,但有时它会反过来发生,有没有办法让“layer_2”等待“layer_1”的结尾?

我的AsyncTask:

% Define your combinations, with neutral grey added to the end of the color choices.
linestyles = {'-', '--', ':', '-.'};
colours = {'red', [0.0, 220.0, 0.0]./255.0, 'blue', 'black', [255.0, 180.0, 0.0]./255.0, [0.0, 128.0, 0.0]./255.0, [0.0, 255.0, 255.0]./255.0, [1.0, 0.0, 1.0], [0.5 0.5 0.5]};
markers = {'d', '*', '+', 'x', 'o', 's', '^', 'v', '.', '>', '<', 'p', 'h'};

% Count the values in each cell array 
ldx = numel(linestyles); % = 4
cdx = numel(colours); % = 9
mdx = numel(markers); % = 13

% Make each cycle the same length
LDX = repmat(1:ldx, [1 cdx*mdx]);
CDX = repmat(1:cdx, [1 ldx*mdx]);
MDX = repmat(1:mdx, [1 ldx*cdx]);

x = 1:10
y = x;
for idx = 1:numel(LDX)
    % Pick out the current combination
    currentLineStyle = LDX(idx);
    currentMarker = MDX(idx);
    currentColour = CDX(idx);

    % Plot your data here...
    line(x, y, 'Color', currentColour, 'LineStyle', currentLineStyle, 'Marker', currentMarker)
end

并在我的progressupdate中:

  protected Void doInBackground(String... params) {

        String ope = params[0];
        switch (ope)
        {
            case "layer_1":
                if(Util.isNetworkAvailable(mContext.getApplicationContext()))
                {
                    getWebservice = WebService.getLayer(COD_MATRICULA);
                    changeAsync = true;
                }
                break;
            case "layer_2":
                if (Util.isNetworkAvailable(mContext.getApplicationContext())) {
                    if(canMade)
                        message = addUserWeb(User);
                    changeAsync = true;
                    callMessage = true;
                }
                else
                {
                    message = null;
                    changeAsync = false;
                }
                break;
        }
        publishProgress();
        return null;
    }

1 个答案:

答案 0 :(得分:0)

您可以在项目中使用两个asyncTask,如下所示

//layer_1 
private class AsyncTaskRunner1 extends AsyncTask<String, String, String> {

    @Override
    protected void onPreExecute() {
    }

    @Override
    protected String doInBackground(String... params) {
       if(Util.isNetworkAvailable(mContext.getApplicationContext()))
            {
                getWebservice = WebService.getLayer(COD_MATRICULA);
                changeAsync = true;
            }

    }

    @Override
    protected void onPostExecute(String result) {
        AsyncTaskRunner2 myTask = new AsyncTaskRunner2();
        myTask.execute();
    }
}

//layer_2 
private class AsyncTaskRunner2 extends AsyncTask<String, String, String> {

    @Override
    protected void onPreExecute() {
    }

    @Override
    protected String doInBackground(String... params) {
       if (Util.isNetworkAvailable(mContext.getApplicationContext())) {
                if(canMade)
                    message = addUserWeb(User);
                changeAsync = true;
                callMessage = true;
            }

    }

    @Override
    protected void onPostExecute(String result) {

    }
}