【问题标题】:How do i send a value from my async task to another new activity?如何将值从我的异步任务发送到另一个新活动?
【发布时间】:2017-08-18 18:10:36
【问题描述】:

我在我的异步任务中调用 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);
>             }
>         });
>     }

}'

【问题讨论】:

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


    【解决方案1】:

    在您的第一个活动上,当您单击按钮时,您可以像这样从下一个活动发送值。

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

    现在如何获得这些先前值的值?为此,在您的 Result Activity 上获取这样的值

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-02-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-24
      • 2014-09-06
      • 2020-02-11
      相关资源
      最近更新 更多