如何将异步任务中的值发送到另一个新活动?

时间:2017-03-25 22:23:13

标签: android android-intent android-asynctask google-cloud-platform

我在异步任务中调用convertResponseToString但是我也有一个按钮,我如何获得logo.feature来显示新活动的输出? 基本上我想在新活动中显示消息。有什么建议吗?

> 'public String convertResponseToString(BatchAnnotateImagesResponse
> response) {
>         String message = "I FOUND THESE THINGS = :\n\n";
> 
>         List<EntityAnnotation> logos = response.getResponses().get(0).getLogoAnnotations();
>         List<EntityAnnotation> labels = response.getResponses().get(0).getLabelAnnotations();
>         if (logos != null) {
>             for (EntityAnnotation logo : logos) {
>                 String s = logo.getDescription();
>                 EditText logodesc=(EditText)findViewById(R.id.editText);
>                 logodesc.setText(s);
>                 message += String.format(Locale.US, "The score is : %.3f & The logo detected is : %s ",
> logo.getScore(),logo.getDescription());
>                 message += "\n\n";
>             }
>         } else {
>             message += "NOTHING FOUND!\n";
>         }
>         if(labels !=null) {
>             for (EntityAnnotation label : labels) {
>                 message += String.format(Locale.US, "The score is: %.3f & The label detected is : %s ", label.getScore(),
> label.getDescription());
>                 message += "\n";
>             }
>         }else{
>             message += "NOTHING FOUND!";
>         }
>         return message;
> 
>     }
>     public void init()
>     {
>         mbutton=(Button)findViewById(R.id.button);
>         mbutton.setOnClickListener(new View.OnClickListener() {
>             @Override
>             public void onClick(View view) {
>                 Intent i = new Intent(MainActivity.this,Result.class);
>                 i.putExtra("Logo");
>                 startActivity(i);
>             }
>         });
>     }
  

}&#39;

1 个答案:

答案 0 :(得分:0)

点击按钮后,在第一个活动中,您可以发送下一个活动的值,如下所示。

Intent i = new Intent(MainActivity.this,Result.class);     
i.putExtra("Logo","whatever message you want to sent");                      
startActivity(i);

现在你怎么能得到这些先前价值?为此,在结果活动上获取类似这样的值

Intent data =getIntent();
String message= data.getStringExtra("Logo");