Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid Widget with ImageView is Invisible Until I Start Moving It
    primarykey
    data
    text
    <p>I've got a widget with an <code>ImageView</code>, whose source I'm setting with a URI to an image on the user's device. I set it with <code>RemoteViews.setImageViewUri()</code> in the <code>onUpdate</code> of the widget's provider. The strangest thing is happening: I can't see the widget or the image while the widget is stationary on my home screen, but when I pick it up and start moving it, the image appears!</p> <p>Here are some screen shots illustrating this:</p> <p><img src="https://i.stack.imgur.com/nfFXV.png" alt="enter image description here"> <img src="https://i.stack.imgur.com/ciuuS.png" alt="enter image description here"></p> <p>Here's the layout for the widget:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/picture_widget_parent" android:layout_width="match_parent" android:layout_height="match_parent" android:padding="@dimen/widget_margin" &gt; &lt;ImageView android:id="@+id/the_picture" android:layout_width="match_parent" android:layout_height="match_parent" android:contentDescription="@string/image_content_description" android:scaleType="centerCrop" /&gt; &lt;/RelativeLayout&gt; </code></pre> <p>And here's my AppWidgetProvider:</p> <pre><code>public class WidgetProvider extends AppWidgetProvider { @Override public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { super.onUpdate(context, appWidgetManager, appWidgetIds); updateAllWidgets(context, appWidgetManager, appWidgetIds); } private void updateAllWidgets(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { PuppyFramePersistenceManager persistenceManager = new PuppyFramePersistenceManager(context); for(int i = 0; i &lt; appWidgetIds.length; i++) { int appWidgetId = appWidgetIds[i]; RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.puppyframe_widget); Intent configIntent = new Intent(context, AlbumsActivity.class); Uri.withAppendedPath(Uri.parse("pw" + i + "://widget/id/"), String.valueOf(appWidgetId)); configIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); PendingIntent configPendingIntent = PendingIntent.getActivity(context, 0, configIntent, 0); remoteViews.setOnClickPendingIntent(R.id.picture_widget_parent, configPendingIntent); String currentAlbumId = persistenceManager.getCurrentAlbumIdForAppWidgetId(appWidgetId); if(currentAlbumId != null) { Uri imageUri = Uri.parse(persistenceManager.getAlbumWithId(currentAlbumId).getImagePaths().get(0)); remoteViews.setImageViewUri(R.id.the_picture, imageUri); } appWidgetManager.updateAppWidget(appWidgetId, remoteViews); } } } </code></pre> <p>This is my AndroidManifest.xml:</p> <pre><code>&lt;manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.boztalay.puppyframe" android:versionCode="1" android:versionName="1.0" &gt; &lt;uses-sdk android:minSdkVersion="14" android:targetSdkVersion="17" /&gt; &lt;application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" &gt; &lt;activity android:name="com.boztalay.puppyframe.configuration.albums.AlbumsActivity" &gt; &lt;intent-filter&gt; &lt;action android:name="android.appwidget.action.APPWIDGET_CONFIGURE" /&gt; &lt;/intent-filter&gt; &lt;/activity&gt; &lt;activity android:name="com.boztalay.puppyframe.configuration.editalbum.EditAlbumActivity" /&gt; &lt;receiver android:name="com.boztalay.puppyframe.widget.PuppyFrameWidgetProvider" &gt; &lt;intent-filter&gt; &lt;action android:name="android.appwidget.action.APPWIDGET_UPDATE" /&gt; &lt;/intent-filter&gt; &lt;meta-data android:name="android.appwidget.provider" android:resource="@xml/puppyframe_info" /&gt; &lt;/receiver&gt; &lt;service android:name="com.boztalay.puppyframe.widget.ScreenOnService"&gt;&lt;/service&gt; &lt;/application&gt; &lt;/manifest&gt; </code></pre> <p>And lastly, this is my widget provider info:</p> <pre><code>&lt;appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android" android:minWidth="40dp" android:minHeight="40dp" android:minResizeWidth="40dp" android:minResizeHeight="40dp" android:updatePeriodMillis="21600000" android:initialLayout="@layout/puppyframe_widget" android:configure="com.boztalay.puppyframe.configuration.albums.AlbumsActivity" android:resizeMode="horizontal|vertical" android:widgetCategory="home_screen"&gt; &lt;/appwidget-provider&gt; </code></pre> <p>Thanks!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload