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 8522879
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T07:15:08+00:00 2026-06-11T07:15:08+00:00

I have been working on a widget for Android. One of the things it

  • 0

I have been working on a widget for Android. One of the things it should do is display the current day of the week and day in the month. I think my code is alright, but for some reason it never updates. The update period in my provider is set to 30 minutes, but I don’t think that should matter (in any case I’ve tried setting it to 1 second and it didn’t change anything). Also, if I make it print the values for the current day of the week and day in the month in LogCat it works fine, so then I really don’t know why it isn’t updating. Please help me out! This is my code:

public class Henk extends AppWidgetProvider {

AppWidgetManager appWidgetManager;
ComponentName componentName;
RemoteViews remoteViews;
LocationManager locationManager;

@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {

    // Update the current date
    this.appWidgetManager = appWidgetManager;
    componentName = new ComponentName(context, Henk.class);
    remoteViews = new RemoteViews(context.getPackageName(), R.layout.main);

    SimpleDateFormat dayofweekformat = new SimpleDateFormat("EEEE");
    Date dayofweekdate = new Date(System.currentTimeMillis());
    String dayofweeklowercase = dayofweekformat.format(dayofweekdate);
    String dayofweek = dayofweeklowercase.toUpperCase();

    SimpleDateFormat monthformat = new SimpleDateFormat("MMMM dd, yyyy");
    Date monthdate = new Date(System.currentTimeMillis());
    String month = monthformat.format(monthdate);

    Log.d("TAG", "----> DAY OF WEEK: " + dayofweek); // Fine in LogCat
    Log.d("TAG", "----> MONTH AND DATE: " + month); // Fine in LogCat

    remoteViews.setTextViewText(R.id.widget_textview1, dayofweek);
    remoteViews.setTextViewText(R.id.widget_textview2, month);

    appWidgetManager.updateAppWidget(componentName, remoteViews);

}
}

EDIT:

I have implemented the solution provided by Doomsknight, so now I think my onUpdate() method should be alright. It still doesn’t show me the day and date yet though. I noticed however, when I was test running it, that onUpdate() is actually executed before my configuration activity is closed. In my configuration activity I have the following code to initialize my widget (at least that’s what it should do), and I think the error is in here then:

public void onClick(View view) {
    // Launch the Widget and close the configuration Activity
    Intent intent2 = new Intent(context, Henk.class);
    PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent2, 0);
    remoteViews.setOnClickPendingIntent(R.id.configuration_button, pendingIntent);
    appWidgetManager.updateAppWidget(appWidgetID, remoteViews);

    Log.d("TAG", "----> APP WIDGET ID: " + appWidgetID);
    Log.d("TAG", "----> REMOTEVIEWS: " + remoteViews);

    Intent result = new Intent();
    result.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetID);
    setResult(RESULT_OK, result);
    finish();
}
  • 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-11T07:15:10+00:00Added an answer on June 11, 2026 at 7:15 am

    You have to bear in mind that there can be many widgets to one application.
    The user can place two or more onto your screen.

    What you have missed is the looping through the Ids. You have passed in some component ID that you generate, rather than the widgets ID and so it does not update the correct widget.

    Widgets can only update minimum 30 mins. Every 1 second will not work, unless you use an AlarmManager. You do not need this in your case.

    @Override
    public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
    
        for (int appWidgetId : appWidgetIds) {
    
                remoteViews = new RemoteViews(context.getPackageName(), R.layout.main);
                SimpleDateFormat dayofweekformat = new SimpleDateFormat("EEEE");
                Date dayofweekdate = new Date(System.currentTimeMillis());
                String dayofweeklowercase = dayofweekformat.format(dayofweekdate);
                String dayofweek = dayofweeklowercase.toUpperCase();
    
                SimpleDateFormat monthformat = new SimpleDateFormat("MMMM dd, yyyy");
                Date monthdate = new Date(System.currentTimeMillis());
                String month = monthformat.format(monthdate);
    
                Log.d("TAG", "----> DAY OF WEEK: " + dayofweek); // Fine in LogCat
                Log.d("TAG", "----> MONTH AND DATE: " + month); // Fine in LogCat
    
                remoteViews.setTextViewText(R.id.widget_textview1, dayofweek);
                remoteViews.setTextViewText(R.id.widget_textview2, month);
    
            appWidgetManager.updateAppWidget(appWidgetId, remoteViews);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been working on a widget for Android. For this I am trying
From the past few days, I have been working on an Android code to
I have been working with SQL Server as a Developer a while. One thing
I have been working on android for the last 6 months. I wonder why
I've been working through an ordered ManyToManyField widget, and have the front-end aspect of
I have a been working on a game for Android and debugging it on
I have a code like this one: $('div.widgetDroppable').droppable({ accept: 'li.widget', drop: function(event, ui) {
I have been working on the problems presented in Python Challenge . One of
Have been working on this question for a couple hours and have come close
I have been working on a large java application. It is quite parallel, and

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.