I have a widget that parses an XML stream and displays its title and image. In this widget, I use a service that periodically changes the content (i.e. the title and image). To do this, I use the timer.When class, we launch this widget, some content is displayed without any problems, but after that it forces to close and shows an error, for example: "RemoteViews for updating the widget exceeds the maximum use of raster memory (used: 2465280 max: 2304000). The total memory may not exceed the time required to fill the device screen once. " Please help me solve this problem ... Thanks in advance
Here is my AppwidgetProvider =>
public class myappwidgetprovider extends AppWidgetProvider { public static String urls="http://www.abc.com/en/rssfeeds/9/latest/rss.xml"; // XML node keys static final String KEY_HEAD = "item"; // parent node //static final String KEY_TITLE = "title"; static final String KEY_DATE = "pubDate"; public static String headflag="english"; public static String[] Title; public static String[] Description; public static String[] Tit; public static String[] Tit2; public static String[] Desc; public static String[] Desc2; public static String[] image; public static TextView flashnews; public static int i=0; public void onUpdate( Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds ) { Log.i("Tag", "onCreateView"); parse(); RemoteViews remoteViews; ComponentName thisWidget = new ComponentName(context,myappwidgetprovider .class); int[] allWidgetIds = appWidgetManager.getAppWidgetIds(thisWidget); Intent intent = new Intent(context.getApplicationContext(), Updatewidget.class); intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, allWidgetIds); context.startService(intent); } public static void parse() { URL url; try { url = new URL(urls); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); if((conn.getResponseCode() == HttpURLConnection.HTTP_OK)){ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); Document doc; doc = db.parse(url.openStream()); doc.getDocumentElement().normalize(); NodeList itemLst = doc.getElementsByTagName("item"); Description = new String[itemLst.getLength()];//........ Title = new String[itemLst.getLength()]; Tit=new String[itemLst.getLength()]; Tit2=new String[itemLst.getLength()]; Desc=new String[itemLst.getLength()]; Desc2=new String[itemLst.getLength()]; image= new String[itemLst.getLength()]; for(int i=0; i < itemLst.getLength(); i++){ Node item = itemLst.item(i); if(item.getNodeType() == Node.ELEMENT_NODE){ Element ielem = (Element)item; NodeList title = ielem.getElementsByTagName("title"); NodeList date = ielem.getElementsByTagName("pubDate"); NodeList description = ielem.getElementsByTagName("description"); Tit[i]= title.item(0).getChildNodes().item(0).getNodeValue(); Desc[i]= description.item(0).getChildNodes().item(0).getNodeValue(); Tit2[i]=Translate.title(Tit[i]); Desc2[i]=Translate.description(Desc[i]); if(headflag=="malayalam") { Desc2[i]=Desc2[i].replace("read more","IqSpXÂ"); } Title[i] =Tit2[i]; if (Desc2[i].contains("<img ")){ String img = Desc2[i].substring(Desc2[i].indexOf("<img ")); String cleanUp = img.substring(0, img.indexOf(">")+1); img = img.substring(img.indexOf("src=") + 5); int indexOf = img.indexOf("'"); if (indexOf==-1){ indexOf = img.indexOf("\""); } img = img.substring(0, indexOf); //setImgLink(img); if(headflag=="malayalam") { String img2=img.replace("files","files/imagecache/android_320"); Description[i]=Desc2[i].replace(img,img2); image[i]=img2; } else { String img2=img.replace("files","files/imagecache/android_1_img"); Description[i]=Desc2[i].replace(img,img2); image[i]=img2; } } else { Description[i] =Desc2[i]; } } } } } catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (DOMException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (ParserConfigurationException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (SAXException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
And here is my service =>
public class Updatewidget extends Service { static String UPDATEMOOD ="UPDATEMOOD"; public Intent newintent; public AppWidgetManager app; public RemoteViews newviews; public int[] newappid; int i=0; @Override public void onStart(final Intent intent, int startId) { Log.i("Tag", "Service Called!!!!!!!!!!!!!"); newintent=intent; int[] allWidgetIds = intent .getIntArrayExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS); newappid=allWidgetIds; final AppWidgetManager appWidgetMan = AppWidgetManager.getInstance(this); app=appWidgetMan; final RemoteViews views = new RemoteViews(this.getPackageName(),R.layout.widget_main); newviews=views; views.setTextViewText(R.id.title, myappwidgetprovider.Title[0]); Bitmap bitmap; try { bitmap = BitmapFactory.decodeStream((InputStream)new URL(myappwidgetprovider.image[0]).getContent()); views.setImageViewBitmap(R.id.imageView4, bitmap); } catch (MalformedURLException e) {
Basim sherif
source share