Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7826483
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T09:26:08+00:00 2026-06-02T09:26:08+00:00

I’m playing around with ICS and Widgets and have stumbled across a problem I

  • 0

I’m playing around with ICS and Widgets and have stumbled across a problem I can’t really seem to debug correctly.

The application has a main activity (WidgetActivity), a widget configure (WidgetConfigure) and a provider (WidgetProvider). The widget’s layout (code below) has a parent LinearLayout and two child LinearLayouts. Both of those children are set to invisible. In my provider’s onUpdate I instantiate a RemoteViews object of that widget, and attempt to set the first LinearLayout to visible.

The widget displays, when placed on the home screen, but the two children don’t (expected). When the onUpdate is called, the child is not set to visible. What I do get, in adb, is a bunch of warnings from StrictMode about the widget not being able to write its state to disk. There’s a policy violation for read and write. Since I’m not actually doing any read and writes anywhere, I assume this is an OS call.

My question – would this StrictMode be causing my views not to change visibility? I understand, on a rough, high level, that StrictMode allows me to identify where I have slow code in my UI Thread. But I don’t just want to blindly override or ser new StrictMode settings without understanding what’s going.

As the adb shows, my onReceive is getting called (and if you wait 180000ms, again), but my child view is not set to visible. And I’m not sure why.

Here’s the code. Widget layout xml, provider, adb trace:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#FFF"
    android:orientation="vertical" >

    <include layout="@layout/widget_next_season" />

    <include layout="@layout/widget_upcoming_game" />

</LinearLayout>

public class WidgetProvider extends AppWidgetProvider {

    private static String TAG = "### WidgetProvider";

    public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
        super.onUpdate(context, appWidgetManager, appWidgetIds);
        Log.d(TAG, "onUpdate");

        RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget);
        Log.d(TAG, "Got Views");
        views.setViewVisibility(R.id.layout_one, View.VISIBLE);
        Log.d(TAG, "Should've set visibility");
    }
}

D/### WidgetProvider(  522): onUpdate
D/### WidgetProvider(  522): Got Views
D/### WidgetProvider(  522): Should've set visibility
I/ActivityManager(   84): Start proc com.android.quicksearchbox for broadcast com.android.quicksearchbox/.CorporaUpdateReceiver: pid=536 uid=10011 gids={3003}
D/dalvikvm(   34): GC_EXPLICIT freed 37K, 4% free 9901K/10243K, paused 4ms+6ms
D/dalvikvm(   84): GC_CONCURRENT freed 496K, 5% free 12726K/13383K, paused 11ms+43ms
D/StrictMode(   84): StrictMode policy violation; ~duration=2436 ms: android.os.StrictMode$StrictModeDiskReadViolation: policy=151 violation=2
D/StrictMode(   84):    at android.os.StrictMode$AndroidBlockGuardPolicy.onReadFromDisk(StrictMode.java:1074)
D/StrictMode(   84):    at libcore.io.BlockGuardOs.open(BlockGuardOs.java:94)
D/StrictMode(   84):    at libcore.io.IoBridge.open(IoBridge.java:390)
D/StrictMode(   84):    at java.io.FileOutputStream.(FileOutputStream.java:88)
D/StrictMode(   84):    at com.android.server.AppWidgetService.writeStateToFileLocked(AppWidgetService.java:1220)
D/StrictMode(   84):    at com.android.server.AppWidgetService.saveStateLocked(AppWidgetService.java:1204)
D/StrictMode(   84):    at com.android.server.AppWidgetService$2.onReceive(AppWidgetService.java:1503)
D/StrictMode(   84):    at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:728)
D/StrictMode(   84):    at android.os.Handler.handleCallback(Handler.java:605)
D/StrictMode(   84):    at android.os.Handler.dispatchMessage(Handler.java:92)
D/StrictMode(   84):    at android.os.Looper.loop(Looper.java:137)
D/StrictMode(   84):    at com.android.server.ServerThread.run(SystemServer.java:744)
D/StrictMode(   84): StrictMode policy violation; ~duration=2301 ms: android.os.StrictMode$StrictModeDiskWriteViolation: policy=151 violation=1
D/StrictMode(   84):    at android.os.StrictMode$AndroidBlockGuardPolicy.onWriteToDisk(StrictMode.java:1048)
D/StrictMode(   84):    at libcore.io.BlockGuardOs.write(BlockGuardOs.java:178)
D/StrictMode(   84):    at libcore.io.IoBridge.write(IoBridge.java:447)
D/StrictMode(   84):    at java.io.FileOutputStream.write(FileOutputStream.java:187)
D/StrictMode(   84):    at com.android.internal.util.FastXmlSerializer.flushBytes(FastXmlSerializer.java:212)
D/StrictMode(   84):    at com.android.internal.util.FastXmlSerializer.flush(FastXmlSerializer.java:233)
D/StrictMode(   84):    at com.android.internal.util.FastXmlSerializer.endDocument(FastXmlSerializer.java:183)
D/StrictMode(   84):    at com.android.server.AppWidgetService.writeStateToFileLocked(AppWidgetService.java:1266)
D/StrictMode(   84):    at com.android.server.AppWidgetService.saveStateLocked(AppWidgetService.java:1204)
D/StrictMode(   84):    at com.android.server.AppWidgetService$2.onReceive(AppWidgetService.java:1503)
D/StrictMode(   84):    at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:728)
D/StrictMode(   84):    at android.os.Handler.handleCallback(Handler.java:605)
D/StrictMode(   84):    at android.os.Handler.dispatchMessage(Handler.java:92)
D/StrictMode(   84):    at android.os.Looper.loop(Looper.java:137)
D/StrictMode(   84):    at com.android.server.ServerThread.run(SystemServer.java:744)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T09:26:16+00:00Added an answer on June 2, 2026 at 9:26 am

    The reason was, in fact, the StrictMode. I have worked around this problem by ensuring my network code is in a Service, not in the onUpdate of the widget. Despite that Android still complains about violating the StrictMode for network and disc access.

    To work around this I modify the StrictMode policy, and reset it when I’m done. I simply call these functions around the network code.

    /**
     * Prevent exceptions from doing disk and network operations in a service
     */
    protected static void setPermissiveThreadPolicy() {
        // set StrictMode to allow network/disk in service
        oldThreadPolicy = StrictMode.getThreadPolicy();
        StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder(oldThreadPolicy).permitNetwork().permitDiskReads().permitDiskWrites().build());
    }
    
    /**
     * Reset thread policy to previously known state for consistency
     */
    protected static void resetThreadPolicy() {
        if (oldThreadPolicy != null) {
            // reset to old policy
            StrictMode.setThreadPolicy(oldThreadPolicy);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a text area in my form which accepts all possible characters from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.