i'm a begginner of android.Shortly what i'm doing is using a simpleAdapater to show a web URL list for practice purpose. however, when i click on the URL,it cause a forceclose error. the logcat shows that
android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?
i already found out some similar problems about this kind of exception.one possible solution is that add the flag before calling startActivity method.for example:
intent.addFlag(FLAG_ACTIVITY_NEW_TASK);
unfortunately,the click event of the web URL is responsed by system automatically. so how can i resolve this problem in my case? And can anyone explain why this problem occured when using simpleAdapter but not ArrrayAdapter?
here is the main code:
public class RSSContentActivity extends ListActivity
{
private SimpleAdapter simpleAdapter;
private ListView lv;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
lv = getListView();
simpleAdapter = new SimpleAdapter(getApplicationContext(), getData(),
R.layout.rss_content_item, new String[]
{"item_link" }, new int[]
{R.id.rss_item_content});
lv.setAdapter(simpleAdapter);
}
private List<Map<String, Object>> getData()
{
List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
Map<String, Object> map = new HashMap<String, Object>();
map.put("item_link",
"http://www.bom.gov.au/vic/warnings/coastalwind.shtml");
list.add(map);
map = new HashMap<String, Object>();
map.put("item_link",
"http://www.bom.gov.au/cgi-bin/wrap_fwo.pl?IDV36050.html");
list.add(map);
map = new HashMap<String, Object>();
map.put("item_link", "http://www.bom.gov.au/products/IDY21000.shtml");
list.add(map);
return list;
}
}
here is the rss_item_content.xml file:
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/rss_item_content"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:autoLink="web"
android:padding="10dp"
android:textAppearance="?android:attr/textAppearanceMedium" >
</TextView>