首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Healthvault_putting数据

Healthvault_putting数据
EN

Stack Overflow用户
提问于 2014-08-21 16:11:02
回答 1查看 27关注 0票数 0

嗨,我正在尝试添加一个新的SDK值到healthvault,当我使用wEIGHT提供的代码时,它写得很好,我拆分了代码,以便与另一个UI.Now一起使用,它给我错误,Logcat显示没有错误。错误消息是“发生异常:空”

这是我的代码

代码语言:javascript
复制
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.example.customlist.R;
import com.microsoft.hsg.Request;
import com.microsoft.hsg.android.HealthVaultService;


import com.microsoft.hsg.android.demo.hv.Weight;
import com.microsoft.hsg.request.SimpleRequestTemplate;

 public class AddWeight extends Activity {

private HealthVaultService service;
//    private Record selectedRecord;
String recd_id = "";
String persn_id = "";
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.addweight);
    service = HealthVaultService.getInstance();
    Intent intent = getIntent();
    recd_id  = intent.getExtras().getString("recd_id");
    persn_id  = intent.getExtras().getString("persn_id");
    Button save = (Button) findViewById(R.id.savebutton);
    save.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            EditText text = (EditText) findViewById(R.id.edt_wght);
            PutWeight putAction = new PutWeight(text.getText().toString());
            putAction.execute();
        }
    });


    Button backpage = (Button) findViewById(R.id.backbutton);
    backpage.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            service.reset();
            Intent i = new Intent(AddWeight.this,WeightActivity.class);
            startActivity(i);
            finish();
        }
   });


}



private class PutWeight extends AsyncTask<Void, Void, Void> {
    private String weight;
    private Exception exception;
    ProgressDialog progressDialog;


    public PutWeight(String weight) {
        this.weight = weight;
        progressDialog = ProgressDialog.show(
                AddWeight.this,
                "",
                "Saving Data",
                true);
    }


    protected Void doInBackground(Void... v) {
        try {

            putWeight(weight);
        } catch(Exception e) {
            exception = e;
        }

        return null;
     }

    /* (non-Javadoc)
     * @see android.os.AsyncTask#onPostExecute(java.lang.Object)
     */
    @Override
    protected void onPostExecute(Void v) {
        progressDialog.dismiss();

        if (exception == null) {
          Intent i=new Intent(AddWeight.this,WeightActivity.class);
          startActivity(i);
          finish();
        } else {
            Toast.makeText(
                AddWeight.this,
                "An error occurred.  " + exception.getMessage(),
                Toast.LENGTH_LONG).show();
        }   
    }   
}
private void putWeight(String value)
{
    Weight weight = new Weight(Double.parseDouble(value));

    SimpleRequestTemplate template = new SimpleRequestTemplate(
            service.getConnection(),
           persn_id,
            recd_id);

    StringBuilder infoBuilder = new StringBuilder();
    infoBuilder.append("<info><thing><type-id>");
    infoBuilder.append(Weight.TYPE);
    infoBuilder.append("</type-id><data-xml>");
    infoBuilder.append(weight.toXml());
    infoBuilder.append("<common/></data-xml></thing></info>");

    Request request = new Request();
    request.setMethodName("PutThings");
    request.setInfo(infoBuilder.toString());
    template.makeRequest(request);
}
}
EN

回答 1

Stack Overflow用户

发布于 2014-08-21 16:23:03

您正在重写AsyncTask构造函数,并且没有调用super()。无论如何,这样做有什么目的吗?您可以在onPreExecute()方法中开始显示对话框,并将weight变量传递给execute方法。只需调整您的AsyncTask,以便doInBackground可以接受参数,并像new PutWeight().execute(text.getText().toString())一样调用它

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25421314

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档