On Sun, Nov 14, 2010 at 11:15 PM, Peter Webb <r.peter.w...@gmail.com> wrote:
> Lets say I have an Activity on top of the stack. It passes an intent
> to another of my apps but doesn't finalise, and the new app is now on
> top of the stack. It sends an intent back to the original application.

Applications do not receive Intents, normally. I am going to assume
for the rest of this reply that you meant "Activity" here...

...in which case, you generally do not "send" an Intent to an
activity. Normally, you start an activity with an Intent. You can use
broadcast Intents to "send" an Intent to an activity, but that
probably will not meet your needs, and does not magically get picked
up by the targeted activity anyway -- you have to register a
BroadcastReceiver for that.

The rest of this reply assumes you are using startActivity() with these Intents.

> This must cause some method to be be run in the original application.

Not necessarily. By default, your original activity is ignored. A new
instance of the same activity class is created via startActivity().
You have to go through some gyrations to get there to be only one
instance of the original activity.

Bear in mind the expected way to do what I think you are describing is
to have the original activity start the second one via
startActivityForResult(), and for the second one to return its result
via setResult() and finish().

> If the original app was not finalised, OnCreate will not be run again,

Not necessarily, as noted above.

> I note there is an onResume method, I
> assume this is always run when an existing app is moved to the top of
> the stack. So I could put getIntent() statements in both OnCreate and
> OnResume methods. This seems wrong, and isn't how the demos generally
> work.

Correct.

> An intent is passed to a Class, and not to a method.

That sentence makes no sense to me, sorry.

> What method is
> actually run when a new intent is received?

If it is a new activity, onCreate() is called. If it is an existing
activity, onNewIntent() is called. Note that, unless you take specific
steps to the contrary, startActivity() will create a new instance of
the activity class, even if you already have a previous instance of
that class floating around.

> Where can I reliably put
> my getIntent() logic to work out what my app really has to do? In
> onResume and OnCreate, or in onRestart or in onNewIntent? Or in some
> other manner? I want to centralise my intent handling logic, but don't
> know the simplest/most reliable method to put it in. Can you make any
> suggestions?

Use startActivityForResult().

-- 
Mark Murphy (a Commons Guy)
http://commonsware.com | http://github.com/commonsguy
http://commonsware.com/blog | http://twitter.com/commonsguy

Warescription: Three Android Books, Plus Updates, One Low Price!

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to