开发者

startActivityForResult doesn't seem to call onActivityResult

开发者 https://www.devze.com 2023-04-10 05:33 出处:网络
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.

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.

I have done using startActivityForResult ().

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

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

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.

This is my previous question : link

Here calling activity:

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

And my receiver activity :

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

    }

And calling activity

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

}

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

I didn't go anywhere..

onActivityResult开发者_Go百科 mehtod.But it didn't go it.

What is wrong in my code.

Please let me know if anybody know this...

Thanks in advance


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

your activity result will go to your activity group.You will not get activity result in your first activity

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.

For example

You have one static object product in your first activity

First Activity

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

don't finish First Activity

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

second activity

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

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

finish()

EDIT

I got the solution for your issue of badTokenException

Here is the solution

CLICK HERE

0

精彩评论

暂无评论...
验证码 换一张
取 消