Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8852897
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:30:55+00:00 2026-06-14T13:30:55+00:00

I am retrieving some HTML from my site and putting it into a TextView.

  • 0

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- How do I make links in a TextView clickable? and a couple of other sources online.

So my code is something like this :

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);

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) :

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)

Any ideas what could be causing the error and how to fix it?

EDIT: Full trace, as requested, below —

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)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T13:30:56+00:00Added an answer on June 14, 2026 at 1:30 pm

    It seems that you initialize the para TextView object with a non-Activity context , which require to set Intent.FLAG_ACTIVITY_NEW_TASK on the Intent that starts the Activity.

    this will solve the problem

    TextView para = new TextView(this); this refer to Activity context

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can anyone point out the flaw in this code? I'm retrieving some HTML with
i am creating a few divs from some JSONP data that i am retrieving
I have some data that I'm retrieving using JSONP from a remote server. The
I am retrieving some configuration from a service and passing this data to the
I am retrieving some data from the server which looks something like this: 1:some
Can anybody help me with retrieving some elements from the following example text: sdfaasdflj
Currently, I'm retrieving some data from a MySQL database table, but the problem is
I´m having some trouble retrieving a collection of strings in a projection: say that
For some reason I'm having a problem retrieving data from my database. It leaves
I'm retrieving an entire HTML document via AJAX - and that works fine. But

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.