1

i used the code below for my listview and textview .

Code:

textcontent.setText(Html.fromHtml(item.get_text()));
textcontent.setAutoLinkMask(Linkify.WEB_URLS);

XML:

<TextView
                android:id="@+id/txtview"
                android:autoLink="web"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:text="put your link here"/>

the link looks like url and i can click it but it generate this exception

android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag.

any idea how to solve this problem ?

1
  • i have the List adapter in other class than the main Activity class and then i create object from the list adapter class from the main activity class and pass to it the context is that maybe the cause of the problem ? Commented Jul 14, 2010 at 22:43

2 Answers 2

10

Don't pass application context to ListAdapter constructor. Pass your main activity instead.

ListAdapter flareAdapter = new ListAdapter(LayoutInflater.from(activity), Items);

Even if you create adapter in some other class you should pass main activity reference anyway.

Sign up to request clarification or add additional context in comments.

2 Comments

thanks for the hint , this is what i did and it works Context aContext ; aContext = this; ListAdapter flareAdapter = new ListAdapter(LayoutInflater.from(aContext), Items);
Thank you so much. I just pass the Activity as context to the adapter. new ListAdapter(this,etc..)
1

Are you sure the click caused that exception not something you want to launch?

As I see you need to add the flags to the intent (not sure what is your intent though)

intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

3 Comments

If so, maybe give us more from the Exception log, let's see the stack trace.
i have the List adapter in other class than the main Activity class and then i create object from the list adapter class from the main activity class and pass to it the context is that maybe the cause of the problem ?
ListAdapter flareAdapter = new ListAdapter(LayoutInflater .from(getApplicationContext()), Items);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.