返回类型片段线程无效

时间:2018-04-23 18:31:20

标签: android multithreading personality-insights

我在Android IDK中创建了一个Thread,为什么它表示无效的返回类型! 我想要的只是显示json Profile来自Thread thread= new Thread(){ if (getActivity()!=null) { getActivity().runOnUiThread(new Runnable() { @Override public void run() { Profile profile = service.getProfile(text); Gson gson = new Gson(); String json = gson.toJson(profile); output.setText(json.toString()); } }); } }; thread.start(); 我想更改片段中的文字

<i><button id="recover-credentials-submit" 
   ng-class="{disabled: disabled, &quot;btn-primary&quot;: true}" 
   ng-disabled="disabled" type="submit" class="btn btn-primary pull-right">
   <span title="send recover email" 
         aria-hidden="true" class="fa fa-key"></span>&nbsp;Send</button>
</i>

1 个答案:

答案 0 :(得分:2)

试试这个

    new AsyncTask<Void, Void, Void> (){
        private String json;

        protected Void doInBackground(Void... voids) {
            Profile profile = service.getProfile(text);
            Gson gson = new Gson();
            json = gson.toJson(profile);
            return null;
        }

        protected void onPostExecute(Void result) {
            output.setText(json);
        }
    }.execute();