This week's book giveaway is in the Android forum.
We're giving away four copies of Create an Uber Clone in 7 Days: Build a real world full stack mobile app in Java and have Shai Almog on-line!
See this thread for details.
Win a copy of Create an Uber Clone in 7 Days: Build a real world full stack mobile app in Java this week in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Calling startActivityForResult crashes app  RSS feed

 
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have an activity(Activity A) and a custom adapter, MyProductsAdapter. In my custom adapter, I would like to call Activity B for result so that Activity A gets the result.

In Activity A:



in MyProductsAdapter:



in MyProductsAdapter's getView():



But the app crashes at the last line. Error message is:  java.lang.ClassCastException: android.support.multidex.MultiDexApplication cannot be cast to android.app.Activity

Please help. If I am unclear, please ask me to elaborate. Thanks.
 
Saloon Keeper
Posts: 4564
115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
getApplicationContext() returns the Application, not the Activity.  While both are subclasses of Context, neither is a subclass of the other, so they can't be substituted for one another. If that code runs in an Activity -as you state- you can just use "this" as the first parameter of the MyProductsAdapter constructor.
 
Alan Blass
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Tim,

Thank you for your answer.

I have changed it; it runs. But before Activity B starts, Activity A's onActivityResult() method is called first. Then Activity B starts.

When Activity B finishes, Activity A's onActivityResult() does not get called.

Here is how I end by Activity B:



Am I doing something wrong? Please help. Thanks.
 
Tim Moores
Saloon Keeper
Posts: 4564
115
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not sure. Does removing "intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);" make a difference?
 
Alan Blass
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Tim,

Yes, it did. Thank you very much for your suggestion.
 
Where all the women are strong, all the men are good looking and all the tiny ads are above average:
Why should you try IntelliJ IDEA ?
https://coderanch.com/wiki/696337/IntelliJ-IDEA
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!