0

I want to pass context of calling activity to called activity so that I can access the spinner present in calling activity Please help.

  • 3
    You really can't. There's no promise the calling activity is even in your app, so they prevent that on purpose. Even if you do something hack to get at it, it won't work the way you think- that other activity has been stopped and its ui will not update. The closest way to do this is to return the new settings as a result when you finish and update the spinner in its owning activity – Gabe Sechan Jan 14 '16 at 18:59
  • 1
    I am calling finish() in the called activity and it goes back to the original activity.How can I detect that my original activity is now at the front so that I can update my spinner at that moment. – Arunim Chopra Jan 15 '16 at 04:12

3 Answers3

1

Sorry, but that is not possible.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Can't I use Parceable. – Arunim Chopra Jan 15 '16 at 04:13
  • @ArunimChopra: No. First, you cannot implement `Parcelable` on `Activity`, because you did not write `Activity`. Second, passing a `Parcelable` extra makes a copy of the `Parcelable` object; the recipient gets that copy. Hence, you would not be able to "access the spinner present in calling activity", because you would be working with a copy. – CommonsWare Jan 15 '16 at 12:09
1

Finally!! I have solved the problem by using startActivityForResult() and getActivityResult() methods. Thank u.

0

You should have a look at PendingIntent. From the docs:

A description of an Intent and target action to perform with it. Instances of this class are created with getActivity(Context, int, Intent, int), getActivities(Context, int, Intent[], int), getBroadcast(Context, int, Intent, int), and getService(Context, int, Intent, int); the returned object can be handed to other applications so that they can perform the action you described on your behalf at a later time. By giving a PendingIntent to another application, you are granting it the right to perform the operation you have specified as if the other application was yourself (with the same permissions and identity). As such, you should be careful about how you build the PendingIntent: almost always, for example, the base Intent you supply should have the component name explicitly set to one of your own components, to ensure it is ultimately sent there and nowhere else.

rupesh jain
  • 3,410
  • 1
  • 14
  • 22