It was all right while I was testing my widget with emulators but when I try to test it on a real device (HTC Desire 816g), I get the following error when I load an Image from url. This is the error:
05-03 12:15:21.679 24313-24393/com.example.macos.ladderapp D/dalvikvm: Alloc : 11653456
05-03 12:15:21.680 24313-24393/com.example.macos.ladderapp I/dalvikvm: "AsyncTask #2" prio=5 tid=31 RUNNABLE
| group="main" sCount=0 dsCount=0 obj=0x424d34d0 self=0x637abb60
| sysTid=24393 nice=10 sched=0/0 cgrp=apps/bg_non_interactive handle=1668947712
| state=R schedstat=( 93174539 4489846 39 ) utm=9 stm=0 core=1
at dalvik.system.VMRuntime.newNonMovableArray(Native Method)
at android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
05-03 12:15:21.682 24313-24393/com.example.macos.ladderapp I/dalvikvm: at android.graphics.BitmapFactory.decodeStreamInternal(BitmapFactory.java:635)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:611)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:649)
at com.example.macos.ladderapp.RetrieveFeedTask.doInBackground(RetrieveFeedTask.java:57)
at com.example.macos.ladderapp.RetrieveFeedTask.doInBackground(RetrieveFeedTask.java:25)
at android.os.AsyncTask$2.call(AsyncTask.java:288)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
And this is the Java code:
protected void onPostExecute(Bitmap bm) {
AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(mcontext);
RemoteViews remoteViews = new RemoteViews(mcontext.getPackageName(), R.layout.simple_widget);
remoteViews.setImageViewBitmap(R.id.REKLAM, bm);
appWidgetManager.updateAppWidget(new ComponentName(mcontext, SimpleWidgetProvider.class), remoteViews);
}
@Override
protected Bitmap doInBackground(Context... contexts) {
Bitmap bm = null;
try {
URL aURL = new URL(mLink);
URLConnection conn = aURL.openConnection();
conn.connect();
InputStream is = conn.getInputStream();
BufferedInputStream bis = new BufferedInputStream(is);
bm = BitmapFactory.decodeStream(bis);
bis.close();
is.close();
} catch (IOException e) {
Log.e(TAG, "Error getting bitmap", e);
}
return bm;
}
This is the widget layout file and I think it causes the
Problem loading widget error. I am trying to load an Imageview (REKLAM) and on top left corner of it a clickable arrow vector(clickview).
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="@dimen/widget_margin"
>
<ImageView
android:id="@+id/clickview"
android:layout_width="50dp"
android:alpha="0.84"
android:layout_alignLeft="@id/REKLAM"
android:src="@drawable/ic_widget_arrow_24dp"
android:layout_height="40dp" />
<ImageView
android:id="@+id/REKLAM"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
/>
</RelativeLayout>