Please don't call startActivity() from an IntentReceiver.  This will
pop your activity up in front of whatever they are doing, and they
will likely curse you loudly.

I am not clear on exactly what you are trying to accomplish, but I
suggest you back up a bit and look at how you want your application to
behave when the user is working with it vs. when it is in the
background.  From that perspective, you probably shouldn't at all be
using an IntentReceiver that is published in your manifest for this,
since that IntentReceiver will run regardless of whether the user is
currently using your app (which is the purpose of being able to
publish intent receivers as top-level components).  Instead, you may
want to have your activity use registerReceiver() to monitor the phone
state while it is running and perform an appropriate action when it is
called -- for example calling startActivity() to switch to the next
desired activity() followed by a finish() to close the current
activity.

Another approach you can take which may be much cleaner is to have a
single activity that watches the phone state and just updates itself
in response to that.  This update could either be in the form of
changing what it is displaying (such as by calling setContentView()
with the desired layout to display), or it could be an ActivityGroup
that switches between embedded activities based on the state.

On Apr 3, 12:12 am, Kenji Hollis <[EMAIL PROTECTED]> wrote:
> Hello all,
>
> Is it possible to switch sub-activity within an Intent Receiver?  I
> wanted to use an IntentReceiver as a top-level dispatcher class that I
> can use as a way to delegate master actions to different Activities.
>
> I have set up an intent receiver object in my manifest file that
> listens for PHONE_STATE, and that works fine.  The problem is, the
> only way I know of to switch to a different action is by calling
> context.startActivity with a NEW_TASK option as the task launch
> option.  This doesn't quite do what I wanted - it starts a brand new
> instance of a sub activity, which goes away when clicking "BACK".
>
> I have added a "registerReceiver" to my main subclass, but the problem
> is, it receives a "PHONE_STATE" action each and every time it
> launches, with the same exact data, and same exact parameters that it
> got from the last PHONE_STATE action.
>
> Is there a smarter way to switch between subactivities from within an
> IntentReceiver?  Is this done by broadcasting the intent instead?  If
> someone has an example, I'd love to see it.  Any help would be greatly
> appreciated.  Thanks!!
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
Announcing the new M5 SDK!
http://android-developers.blogspot.com/2008/02/android-sdk-m5-rc14-now-available.html
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to