Android 小部件更新的RemoteView超过最大位图内存使用量错误

Android 小部件更新的RemoteView超过最大位图内存使用量错误,android,android-widget,android-service,Android,Android Widget,Android Service,我有一个小部件,可以解析xml提要并显示其标题和图像。在这个小部件中,我使用一个定期更改内容(即标题和图像)的服务。为此,我使用计时器类。当我们运行这个小部件时,一些内容显示没有任何问题,但经过一段时间后,它强制关闭并显示错误,如“用于小部件更新的RemoteView超过最大位图内存使用量(已使用:2465280最大:2304000)总内存不能超过填充设备屏幕一次所需的内存”。请有人帮助我解决此问题…提前感谢 这是我的AppwidgetProvider=> public class myapp

我有一个小部件,可以解析xml提要并显示其标题和图像。在这个小部件中,我使用一个定期更改内容(即标题和图像)的服务。为此,我使用计时器类。当我们运行这个小部件时,一些内容显示没有任何问题,但经过一段时间后,它强制关闭并显示错误,如“用于小部件更新的RemoteView超过最大位图内存使用量(已使用:2465280最大:2304000)总内存不能超过填充设备屏幕一次所需的内存”。请有人帮助我解决此问题…提前感谢

这是我的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();
            }
     }

}
公共类myappwidgetprovider扩展了AppWidgetProvider{
公共静态字符串URL=”http://www.abc.com/en/rssfeeds/9/latest/rss.xml";
//XML节点密钥
静态最终字符串KEY\u HEAD=“item”;//父节点
//静态最终字符串键\u TITLE=“TITLE”;
静态最终字符串键\u DATE=“pubDate”;
公共静态字符串headflag=“英语”;
公共静态字符串[]标题;
公共静态字符串[]说明;
公共静态字符串[]Tit;
公共静态字符串[]Tit2;
公共静态字符串[]Desc;
公共静态字符串[]Desc2;
公共静态字符串[]图像;
公共静态文本视图flashnews;
公共静态int i=0;
公共void onUpdate(上下文上下文,AppWidgetManager AppWidgetManager,int[]AppWidgetId)
{
Log.i(“标记”、“onCreateView”);
parse();
远程视图远程视图;
ComponentName thisWidget=新组件名(上下文,myappwidgetprovider.class);
int[]allWidgetIds=appWidgetManager.getAppWidgetIds(thisWidget);
Intent Intent=新的Intent(context.getApplicationContext(),
Updatewidget.class);
intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_id,allWidgetIds);
上下文。startService(意图);
}
公共静态void parse()
{
网址;
试一试{
url=新url(url);
HttpURLConnection conn=(HttpURLConnection)url.openConnection();
if((conn.getResponseCode()==HttpURLConnection.HTTP_OK)){
DocumentBuilderFactory dbf=DocumentBuilderFactory.newInstance();
DocumentBuilder db=dbf.newDocumentBuilder();
文件文件;
doc=db.parse(url.openStream());
doc.getDocumentElement().normalize();
nodelistitemlst=doc.getElementsByTagName(“项”);
Description=新字符串[itemLst.getLength()];/。。。。。。。。
Title=新字符串[itemLst.getLength()];
Tit=新字符串[itemLst.getLength()];
Tit2=新字符串[itemLst.getLength()];
Desc=新字符串[itemLst.getLength()];
Desc2=新字符串[itemLst.getLength()];
image=新字符串[itemLst.getLength()];
对于(int i=0;i

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) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
         appWidgetMan.updateAppWidget(allWidgetIds, views); 

         new ProgressAsyncTask().execute();








    }



     public class ProgressAsyncTask extends 
        AsyncTask<Void, Integer, Void> {

        @Override
        protected Void doInBackground(Void... params) {
            // TODO Auto-generated method stub
             int delay = 5000; // delay for 5 sec.

             int period = 5000; // repeat every sec.

             Timer timer = new Timer();
              timer.scheduleAtFixedRate(new TimerTask() {

                     public void run() {
                         i++;
                         if(i==5)
                         {
                             i=0;
                         }

                         int[] allWidgetIds = newintent
                                    .getIntArrayExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS);
                                 newviews.setTextViewText(R.id.title, myappwidgetprovider .Title[i]);
                         Bitmap bitmap;
                            try {
                                bitmap = BitmapFactory.decodeStream((InputStream)new URL(myappwidgetprovider .image[i]).getContent());


                                newviews.setImageViewBitmap(R.id.imageView4, bitmap);
                            } catch (MalformedURLException e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                            } catch (IOException e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                            }
                         app.updateAppWidget(allWidgetIds, newviews); 
                                 }


                     }, delay, period);
            return null;
        }
     }

    @Override
    public IBinder onBind(Intent intent) {
        // TODO Auto-generated method stub
        return null;
    }





}
公共类Updatewidget扩展服务{
静态字符串updatemod=“updatemod”;
公众意向;
公共AppWidgetManager应用程序;
公共远程视图新视图;
公共int[]newappid;
int i=0;
@凌驾
公共无效启动(最终目的,int startId){
Log.i(“标签”,“服务呼叫!!!!!!!”);
新意图=意图;
int[]allWidgetIds=intent
.getIntArrayExtra(AppWidgetManager.EXTRA_APPWIDGET_id);
newappid=allWidgetIds;
最终AppWidgetManager-appWidgetMan=AppWidgetManager.getInstance(此);
app=appWidgetMan;
最终远程视图=新远程视图(this.getPackageName(),R.layout.widget_main);
新视图=视图;
views.setTextViewText(R.id.title,myappwidgetprovider.title[0]);
位图;
试一试{
位图=BitmapFactory.decodeStream((InputStream)新URL(myappwidgetprovider.image[0]).getContent());
views.setImageViewBitmap(R.id.imageView4,位图);
}捕获(格式错误){
//TODO自动生成的捕捉块
e、 printStackTrace();
}捕获(IOE异常){
//TODO自动生成的捕捉块
e、 printStackTrace();
}
updateAppWidgetMan.UpdateAppWidgetId(所有WidgetId、视图);
新建ProgressAsyncTask().execute();
}
公共类ProgressAsyncTask扩展
异步任务{
@凌驾
受保护的Void doInBackground(Void…参数){
    Glide.with(mContext)
        .load(imageUrl)
        .override(480, 342)