startActivityForResult似乎并不来电的onActivityResult [英] startActivityForResult doesn't seem to call onActivityResult

查看:66
本文介绍了startActivityForResult似乎并不来电的onActivityResult的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户点击按钮,它要调用该对话框包含ListView.After用户编程选择的产品的产品列表中的对话框 - 它应该来到previuous活动。

When The user Click on the button it want to call the dialog- that dialog contain list of product in ListView.After user slect the product it should come to previuous activity.

我已经做了使用 startActivityForResult()

有aresome issue.My调用活动处于正常活动标签,在标签活动组正常标签activty。

There aresome issue.My calling activity is in normal tab activity that normal tab activty in Tab Activity Group.

Actualy我想在drrop下降(微调)。在我scanerio我不能让context.It awalys给予 Android的微调错误的事:android.view.WindowManager $ BadTokenException:无法添加窗口

Actualy i want to do in drrop down(Spinner).In my scanerio i couldn't get context.It awalys give Android Spinner Error : android.view.WindowManager$BadTokenException: Unable to add window

所以,我必须改变我的设计是这样的:当用户点击buttion其加载产品列表中ListView.After挑选产品,它回来previous活动

So I have change to my design like this: When User click buttion it load the list of product in ListView.After pick the product, it come back to previous activity.

<一个href=\"http://stackoverflow.com/questions/7609519/android-spinner-error-android-view-windowmanagerbadtokenexception-unable-to-a\">This是我的previous问题:链接

下面调用活动:

  //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);
       }
   });

和我的接收器的工作:

  @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(); 

    }

和调用活动

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

}

我在呼唤活性放这样写code(的onActivityResult );标签主要Activty也。

I have written this code(onActivityResult) in calling activity & Tab main Activty also.

我没有去任何地方。

的onActivityResult me​​htod.But没去了。

onActivityResult mehtod.But it didn't go it.

什么是错误的,我code。

What is wrong in my code.

请让我知道如果有人知道这...

Please let me know if anybody know this...

在此先感谢

推荐答案

我有同样的问题,我是用 startActivityForResult()活动组时

I have same issue when I was using startActivityForResult() with activity group.

您的活动的结果会去你的活动group.You在你第一次活动将无法获得活动结果

所以,你可以通过一个公用静态对象在第一个活动解决这个问题,当你调用第二个活动,你必须分配从第二activity.and您的第一个活动对象,然后完成第二个活动,使您的第一项活动将继续工作,您可以通过在第一activity.You覆盖 onResume()方法更新你的UI要检查你的对象分配或未验证的天气。

So you can solve this issue by taking one public static object in your first activity and when you call second activity you have to assign your first activity object from second activity.and then finish second activity so that your first activity will resume and you can update your ui by overriding onResume() method in first activity.You have to check validation weather your object is assigned or not.

例如

您有一个静态对象的产品在你的第一个活动。

You have one static object product in your first activity

第一个活动

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

don't finish First Activity

您必须覆盖 onResume()方法,然后你可以使用它是由次活动指定的产品对象

You have to override onResume() method and then you can use product object which is assigned by second activity

第二项活动

FirstActivity.product.setName(name);
FirstActivity.product.setPrice(price);

在指定的产品对象,你必须完成第二项活动

After assign the product object you have to finish second activity like

finish()

修改

我得到了解决您badTokenException的问题

I got the solution for your issue of badTokenException

下面是解决方案

<一个href=\"http://stackoverflow.com/questions/7609519/android-spinner-error-android-view-windowmanagerbadtokenexception-unable-to/7631687#7631687\">CLICK这里

这篇关于startActivityForResult似乎并不来电的onActivityResult的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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