When calling startActivity, the new activity will live in the same screen stack (context) as the caller. Sometime, the caller may not have an activity context, for instance, starting an activity from Broadcastreceive.onReceive() method, or starting an activity from a service. In these cases, call startActivity will cause an exception of “Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK”, since the new activity does not have a context to live in.

To fix the issue, setting FLAG_ACTIVITY_NEW_TASK to the intent as follows, then a new context will be created for the new activity.