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

  • SEARCH
  • Home
  • 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 6778591
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:17:02+00:00 2026-05-26T16:17:02+00:00

I’m trying to make a widget, for which the user has to provide a

  • 0

I’m trying to make a widget, for which the user has to provide a name. Based on that name, data is collected and shown. In the widget is a refresh button to refresh this data.

The problem is sharing this name between the configuration class and the AppWidgetProvider class. What I have tried:

  • Just use an EditText in the widget. In the config class, set the name in the EditText, and retrieve it in the AppWidgetProvider class. This doesn’t work, because I can’t find a way to retrieve the text in the AWP.
  • Use SharedPreferences:

In the config class:

c = SelectWidgetStationActivity.this;

// Getting info about the widget that launched this Activity.
Intent i = getIntent();
Bundle extras = i.getExtras();
if (extras != null)
    awID = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID);

SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(c);
prefs.edit().putString("widgetname" + awID, name);
prefs.edit().commit();

In the AWP class:

@Override
public void onReceive(Context context, Intent intent) {
    if (intent.getAction().equals(ACTION_WIDGET_RECEIVER)) { //ACTION_WIDGET_RECEIVER is the action fired by the refresh button
        this.onUpdate(context, AppWidgetManager.getInstance(context), AppWidgetManager.getInstance(context).getAppWidgetIds(new ComponentName("com.app.myapp", "com.app.myapp.MyWidgetProvider")));
    }
}

@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);

for (int widgetId : appWidgetIds) {
        name = prefs.getString("widgetname" + widgetId, "N/A"));
    //more code

name keeps giving me “N/A”. I’ve checked that awID and widgetId are equal.
This is probably due to the fact that I’m using different contexts? (Just guessing here)

So what is a way to solve this problem?

Edit
When I’m printing the contexts on screen I get the following:

  • config class: com.app.myapp.WidgetConfigActivity@40774d18

  • AWP class: android.app.ReceiverRestrictedContext@406ad290

  • 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-05-26T16:17:03+00:00Added an answer on May 26, 2026 at 4:17 pm

    Just went through this again out of curiousity and noticed this:

    prefs.edit().putString("widgetname" + awID, name);
    prefs.edit().commit();
    

    This gives you 2 different Editor instances.
    What you do here is get one editor, put in the preference and leave it alone. Then you get a new (unchanged) editor and just commit it (= no changes are written). Just tested that on a small project, doesn’t commit correctly as intended.

    So try to substitute the code with something like this:

    Editor e = prefs.edit();
    e.putString("widgetname" + awID, name);
    e.commit();
    

    or chain the commit in

    prefs.edit().putString("widgetname" + awID, name).commit();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I've got a string that has curly quotes in it. I'd like to replace
I'm trying to create an if statement in PHP that prevents a single post
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I used javascript for loading a picture on my website depending on which small
I have a French site that I want to parse, but am running into

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.