Clicking HTML link in TextView fires weird AndroidRunTimeException
<p>I am retrieving some HTML from my site and putting it into a TextView. This HTML might contain anchor tags that point to web pages, emails, etc. I am trying to make these links click-able in a way such that when the user clicks on it, the default browser opens the web page. I am doing this by following the instructions on this answer- <a href="http://stackoverflow.com/questions/2734270/how-do-i-make-links-in-a-textview-clickable">How do I make links in a TextView clickable?</a> and a couple of other sources online.</p>

<p>So my code is something like this : </p>

<pre><code>TextView para=new TextView(getApplicationContext());    
LayoutParams lpfortext=new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
lpfortext.setMargins(10, 10, 10, 10);
para.setText(Html.fromHtml(e.html()));
para.setMovementMethod(LinkMovementMethod.getInstance());
para.setLinksClickable(true); //error exists on removing this
para.setAutoLinkMask(Linkify.ALL);  //error exists on removing this
para.setLayoutParams(lpfortext);
</code></pre>

<p>But when I actually click on a link in the app (on an ICS phone, haven't tested on an emulator yet), I get the following error (a snapshot of the stack trace, full text at the end) : </p>

<pre><code>11-18 13:17:51.503: E/AndroidRuntime(6010): android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity  context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?
11-18 13:17:51.503: E/AndroidRuntime(6010):     at android.app.ContextImpl.startActivity(ContextImpl.java:1095)
11-18 13:17:51.503: E/AndroidRuntime(6010):     at android.content.ContextWrapper.startActivity(ContextWrapper.java:276)
11-18 13:17:51.503: E/AndroidRuntime(6010):     at android.text.style.URLSpan.onClick(URLSpan.java:62)
11-18 13:17:51.503: E/AndroidRuntime(6010):     at android.text.method.LinkMovementMethod.onTouchEvent(LinkMovementMethod.java:212)
</code></pre>

<p>Any ideas what could be causing the error and how to fix it?</p>

<p><strong>EDIT:</strong> Full trace, as requested, below --</p>

<pre><code>11-18 13:45:09.741: E/AndroidRuntime(7946): FATAL EXCEPTION: main
11-18 13:45:09.741: E/AndroidRuntime(7946): android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity  context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?
11-18 13:45:09.741: E/AndroidRuntime(7946):     at android.app.ContextImpl.startActivity(ContextImpl.java:1095)
11-18 13:45:09.741: E/AndroidRuntime(7946):     at android.content.ContextWrapper.startActivity(ContextWrapper.java:276)
11-18 13:45:09.741: E/AndroidRuntime(7946):     at android.text.style.URLSpan.onClick(URLSpan.java:62)
11-18 13:45:09.741: E/AndroidRuntime(7946):     at android.text.method.LinkMovementMethod.onTouchEvent(LinkMovementMethod.java:212)
11-18 13:45:09.741: E/AndroidRuntime(7946):     at android.widget.TextView.onTouchEvent(TextView.java:8835)
11-18 13:45:09.741: E/AndroidRuntime(7946):     at android.view.View.dispatchTouchEvent(View.java:5579)
11-18 13:45:09.741: E/AndroidRuntime(7946):     at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1965)
11-18 13:45:09.741: E/AndroidRuntime(7946):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1734)
11-18 13:45:09.741: E/AndroidRuntime(7946):     at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1965)
11-18 13:45:09.741: E/AndroidRuntime(7946):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1734)
11-18 13:45:09.741: E/AndroidRuntime(7946):     at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1965)
11-18 13:45:09.741: E/AndroidRuntime(7946):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1734)
11-18 13:45:09.741: E/AndroidRuntime(7946):     at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1965)
11-18 13:45:09.741: E/AndroidRuntime(7946):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1734)
11-18 13:45:09.741: E/AndroidRuntime(7946):     at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1965)
11-18 13:45:09.741: E/AndroidRuntime(7946):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1734)
11-18 13:45:09.741: E/AndroidRuntime(7946):     at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1965)
11-18 13:45:09.741: E/AndroidRuntime(7946):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1734)
11-18 13:45:09.741: E/AndroidRuntime(7946):     at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1982)
11-18 13:45:09.741: E/AndroidRuntime(7946):     at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1441)
11-18 13:45:09.741: E/AndroidRuntime(7946):     at android.app.Activity.dispatchTouchEvent(Activity.java:2421)
11-18 13:45:09.741: E/AndroidRuntime(7946):     at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1930)
11-18 13:45:09.741: E/AndroidRuntime(7946):     at android.view.View.dispatchPointerEvent(View.java:5759)
11-18 13:45:09.741: E/AndroidRuntime(7946):     at android.view.ViewRootImpl.deliverPointerEvent(ViewRootImpl.java:2970)
11-18 13:45:09.741: E/AndroidRuntime(7946):     at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2529)
11-18 13:45:09.741: E/AndroidRuntime(7946):     at android.view.ViewRootImpl.processInputEvents(ViewRootImpl.java:869)
11-18 13:45:09.741: E/AndroidRuntime(7946):     at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2538)
11-18 13:45:09.741: E/AndroidRuntime(7946):     at android.os.Handler.dispatchMessage(Handler.java:99)
11-18 13:45:09.741: E/AndroidRuntime(7946):     at android.os.Looper.loop(Looper.java:154)
11-18 13:45:09.741: E/AndroidRuntime(7946):     at android.app.ActivityThread.main(ActivityThread.java:4945)
11-18 13:45:09.741: E/AndroidRuntime(7946):     at java.lang.reflect.Method.invokeNative(Native Method)
11-18 13:45:09.741: E/AndroidRuntime(7946):     at java.lang.reflect.Method.invoke(Method.java:511)
11-18 13:45:09.741: E/AndroidRuntime(7946):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
11-18 13:45:09.741: E/AndroidRuntime(7946):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
11-18 13:45:09.741: E/AndroidRuntime(7946):     at dalvik.system.NativeStart.main(Native Method)
</code></pre>
