title: Android Widget Configuration with SharedPreferences
body: <p>i want to let the user define a username when starting a homescreen widget im working on. But im having troubles with storing and accessing this value in my widget. What i do at the moment is creating a Configuration Activity which gets started when the widget is created. Therefore i defined it in the manifest file as follows (i also defined it in the widgetprovider.xml):</p>
  
  <pre><code>    &lt;activity android:name=".ExampleAppWidgetConfigure"&gt;
         &lt;intent-filter&gt;
              &lt;action android:name="android.appwidget.action.APPWIDGET_CONFIGURE" /&gt;
         &lt;/intent-filter&gt;
      &lt;/activity&gt;
  </code></pre>
  
  <p>The Configuration Activity then allows the user to enter a username which will be stored in the <code>SharedPreferences</code> of the Widget:</p>
  
  <pre><code>    SharedPreferences.Editor prefs = context.getSharedPreferences(PREFS_NAME, MODE_WORLD_READABLE).edit();
      prefs.putString("username", text);
      prefs.commit();
  </code></pre>
  
  <p>My question is how do i access this value? In my widget class i want to have an instance variable like:</p>
  
  <pre><code>final String userName = ...; //load the username here.
  </code></pre>
  
  <p>But how do i retrieve the username in my widget? The problem is the widget is a subclass of <code>AppWidgetProvider</code> from which i can't access the <code>SharedPreferences</code> (because <code>AppWidgetProvider</code> is not a subclass of <code>Context</code>). I thought about storing the username in the strings.xml file which also doesnt seem to be possible. Is using <code>SharedPreferences</code> the right way at all? I also thought about setting the username to a <code>TextView</code> of my widget, which is later on supposed to display the username. But i need the username in my class for some server requests and it seems there is no way to get the text of a <code>TextView</code> in a widget...only the setter <code>setTextViewText(String text)</code> is defined. </p>
  
  <p>How can i retrieve the username?</p>