startActivityForResult似乎没有调用onActivityResult

Pir*_*aba 3 android

当用户单击按钮时,它想要调用对话框 - 该对话框包含ListView中的产品列表.用户选择产品后,它应该进入上一级活动.

我已经完成了使用startActivityForResult ().

存在一些问题.我的调用活动处于正常选项卡活动中,即Tab活动组中的常规选项卡活动.

Actualy我想在drrop down(Spinner).在我的scanerio我无法得到上下文.它是awalys给 Android Spinner Error : android.view.WindowManager$BadTokenException: Unable to add window

所以我改变了我的设计:当用户点击它时,它会在ListView中加载产品列表.选择产品后,它会回到之前的活动.

这是我之前的问题:链接

这里呼叫活动:

  //Click Product button
   l_prod.setOnClickListener(new OnClickListener() {
       public void onClick(View v) {
            Intent showContent = new Intent(LineDiscountActivity.this,ListProductActivity.class);
            Bundle bundle = new Bundle();
            bundle.putString("Activity", "LineDiscountActivity");
            bundle.putString("RetailerName", retailerName);
            bundle.putString("RetailerCode", retailerCode);
            showContent.putExtra("discountProduct", discountList);
            showContent.putExtras(bundle);
            getParent().startActivityForResult(showContent, 5);
       }
   });
Run Code Online (Sandbox Code Playgroud)

我的接收器活动:

  @Override
  protected void onListItemClick(ListView l, View v, int position, long id) {
        super.onListItemClick(l, v, position, id);
            Object o = this.getListAdapter().getItem(position);
            String book = o.toString();
            Intent i = new Intent();
            Bundle bundle = new Bundle();
            bundle.putString("Activity", "ListProductActivity");
            bundle.putString("RetailerName", retailerName);
            bundle.putString("RetailerCode", retailerCode);
            bundle.putString("seletcedProductCode", products.get(position).getProductCode());
            bundle.putString("seletcedProductName", products.get(position).getDescription());
            bundle.putDouble("seletcedProductQty", products.get(position).getAvailableQuantity());
            i.putExtra("discountProduct", discountList);
            i.putExtras(bundle);
            if (getParent() == null) {
                setResult(Activity.RESULT_OK, i);
            } else {
                getParent().setResult(Activity.RESULT_OK, i);
            }
            ListProductActivity.this.finish(); 

    }
Run Code Online (Sandbox Code Playgroud)

并呼吁活动

 @Override
protected  void onActivityResult(int requestCode, int resultCode, Intent data) {
//  super.onActivityResult(requestCode, resultCode, data);
    Log.i("-requestCode from LineDisocunt--" ,"" + requestCode);

}
Run Code Online (Sandbox Code Playgroud)

我已经onActivityResult在调用activity和Tab main Activty中编写了这段代码().

我没去任何地方..

onActivityResult mehtod.But它没有去.

我的代码有什么问题.

如果有人知道这个,请告诉我......

提前致谢

Dha*_*dra 6

我有当我使用同样的问题startActivityForResult()activity group.

您的活动结果将转到您的活动组.您的第一项活动不会获得活动结果

因此,您可以通过在第一个活动中使用一个公共静态对象来解决此问题,当您调用第二个活动时,您必须从第二个活动分配您的第一个活动对象.然后完成第二个活动,以便您的第一个活动将恢复,您可以更新onResume()在第一次活动中通过覆盖方法来确定你的ui.你必须检查你的对象被分配的验证天气.

例如

您的第一个活动中有一个静态对象产品

第一项活动

public static Product product;
start second activity
startactivity(this, SecondActivity.class);

don't finish First Activity
Run Code Online (Sandbox Code Playgroud)

您必须覆盖onResume()方法,然后您可以使用由第二个活动分配的产品对象

第二项活动

FirstActivity.product.setName(name);
FirstActivity.product.setPrice(price);
Run Code Online (Sandbox Code Playgroud)

分配产品对象后,您必须完成第二个活动,如

finish()
Run Code Online (Sandbox Code Playgroud)

编辑

我为你的badTokenException问题找到了解决方案

这是解决方案

点击这里