The startActivity() methods require the calling context to be an
Activity - otherwise the 'FLAG_ACTIVITY_NEW_TASK' flag is required.
This is why when you try to start an activity from the Application
object, or a Receiver you must specify this flag.

See: 
http://developer.android.com/reference/android/app/Activity.html#startActivity(android.content.Intent)
(note that it specifical mentions "This implementation overrides the
base version, providing information about the activity performing the
launch. Because of this additional information, the
FLAG_ACTIVITY_NEW_TASK launch flag is not required")

Doug

On Jun 22, 9:37 pm, ani <[email protected]> wrote:
> Guys,
>
> I would like to know the reason behind this behaviour.I have a
> broadcast reciever and in onrecieve i am trying to start an
> activity,however if i am not giving the flags it is giving an
> exception .On declaring the flags it is working perfectly fine,why?
>
> I was under the impression that onRecieve runs in the main UI thread
> and we can launch an activity in onRecieve.Error given by the emulator
> is self explanatory but still why do i need to create an activity in a
> new task(only in onRecieve)?
>
> onRecieve {
> Intent intent4activity2 = new Intent
> ("android.intent.action.activity2");
> //intent4activity2.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
> arg0.startActivity(intent4activity2);
>
> }
>
> regards,
> ani
--~--~---------~--~----~------------~-------~--~----~
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]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to