3

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 mehtod.But it didn't go it.

What is wrong in my code.

Please let me know if anybody know this...

Thanks in advance

3
  • Did you make this activity as single task activity in manifest? if yes then onactivity result will not work. Commented Oct 4, 2011 at 9:07
  • I have written activity in manifest file like this '<activity android:name=".sales.ListProductActivity" android:theme="@android:style/Theme.Dialog"> </activity>' .I couldn't get it what is single task activity.? please help me Commented Oct 4, 2011 at 9:11
  • if you didn't write android:launchMode="singleTask" then it should be work.. check this example saigeethamn.blogspot.com/2009/08/… Commented Oct 4, 2011 at 9:21

1 Answer 1

6

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

Sign up to request clarification or add additional context in comments.

1 Comment

I'm sorry, but using static variables across the whole app is not a solution !

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.