WRONG的onActivityResult()被调用 [英] WRONG onActivityResult() being called

查看:174
本文介绍了WRONG的onActivityResult()被调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2个活动A,B和两者都使用的onActivityResult()在其中。

I have 2 activities A, B and both are using onActivityResult() in them.

这个过程:


  1. 的onActivityResult()在一个工作的罚款。

  2. 我有两个的onActivityResult()的活性(code以下所示)乙。首先一个作为可点击的TextView 这也是工作的罚款。其他如按钮

  1. onActivityResult() in A works fines.
  2. I have two onActivityResult()(shown in code below) in Activity B .First one as a clickable TextView which is also working fine. The other as Button.

我现在面临的问题是在其中假设把从B和显示的子活动一个位图在B中的ImageView按钮。当我点击它带我到按钮的的onActivityResult()活性的的。

The problem I'm facing is in the Button which is suppose to bring a Bitmap from sub-activity of B and display in a ImageView in B. . When I click the Button it takes me to the onActivityResult() of the Activity A.

startActivityForResult()在活动B的按钮:

int capSig = arg0.getId();
if(capSig == R.id.capSig)      //Button  which takes me to sub-activity of B
{
    Intent goToCapSignatures = new Intent(this, CaptureSignature.class);
    startActivityForResult(goToCapSignatures, GET_SIG);

}

如何我改变ByteArray的位图和发送位图到活动乙:

how i'm changing ByteArray to Bitmap and sending the Bitmap to Activity B:

Bitmap returnedBitmap = Bitmap.createBitmap(mContent.getWidth(),
                 mContent.getHeight(), Bitmap.Config.ARGB_8888);
         Canvas canvas = new Canvas(returnedBitmap);
         Drawable bgDrawable = mContent.getBackground();
         if (bgDrawable != null)
             bgDrawable.draw(canvas);
         else
             canvas.drawColor(Color.WHITE);
         mContent.draw(canvas);

         ByteArrayOutputStream bs = new ByteArrayOutputStream();
         returnedBitmap.compress(Bitmap.CompressFormat.PNG, 50, bs);
         byte[] byteArray = bs.toByteArray();
         Bitmap bitmap = BitmapFactory.decodeByteArray(byteArray , 0, byteArray.length);



         //send the captured signature to Check and Operations page
         Intent returncapSigIntent = new Intent();
         returncapSigIntent.putExtra("signature",bitmap);
        setResult(RESULT_OK, returncapSigIntent);
        finish();

的onActivityResult()在活动B:

protected void onActivityResult(int requestCode, int resultCode, Intent data) 
{
      if (requestCode == GET_NOTES)        // For textview (working fine)
      {
        if(resultCode == RESULT_OK)
        {
            if (data.hasExtra("notes ready")) 
        {
            String readyNotes = data.getExtras().getString("notes ready");
            showNotesFromNotesClass.setText(readyNotes);
        }
      }

      if (requestCode == GET_SIG)         // for Button - this isn't being  
                                                      called instead 
      {
          if(resultCode == RESULT_OK)
          {
            if (data.hasExtra("signature")) 

                //display Bitmap in an ImageView

                capturedSigImageFromCapSigclass = (Bitmap) data.getExtras().get("signature");
                imgSig.setImageBitmap(capturedSigImageFromCapSigclass);
            }
          }

    }
      }
}

的onActivityResult()在活动A:(这被称为代替

onActivityResult() in Activity A:(This in being called instead.

protected void onActivityResult(int requestCode, int resultCode, Intent data) 
{

      if (resultCode == RESULT_OK && requestCode == REQUEST_APPLIANCE) {
        if (data.hasExtra("selected appliance")) 
        {
            String selectedAppType = data.getExtras().getString("selected appliance");
            tvApplianceType.setText(selectedAppType);
          Toast.makeText(this, data.getExtras().getString("selected appliance"),
            Toast.LENGTH_SHORT).show();
        }
      }
    }

我知道我在做什么工作。请给我一些指点或指导我要去哪里wrong.It将pciated多少AP $ P $正如我已经花这个逻辑天,没有在任何地方获得。谢谢

I'm sure I'm doing something work. please give me some pointers or guidance where i'm going wrong.It will be much appreciated as I have already spend days on this logic and not getting anywhere. Thanks

推荐答案

您可以简单地更改每个活动的要求code值,以确保只有一个被称为是肯定的。

You can simply change the requestCode value on each activity to make sure that only one is called for sure.

请求code只是诠释的常数,它们只是重新presentatives!

requestsCode are simply int constants, they're only representatives!

private static final int GET_NOTES = 0;

...

private static final int GET_SIG = 1;
...

private static final int REQUEST_APPLIANCE = 2;

这应该足够多样化的结果。

This should be enough to diversify the results

这篇关于WRONG的onActivityResult()被调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆