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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T15:05:14+00:00 2026-06-14T15:05:14+00:00

The TextView in my widgetis set correctly with the correct info when it’s getting

  • 0

The TextView in my widgetis set correctly with the correct info when it’s getting placed at the home screen. But when I update the info in the main app, the widget still shows the old info.

Manifest:

<receiver android:name=".WidgetProvider" android:label="@string/app_name" android:exported="false">
    <intent-filter>
        <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
    </intent-filter>

    <meta-data android:name="android.appwidget.provider" android:resource="@xml/widget" />
</receiver>

WidgetProvider.java:

package com.example.huskeliste;

import android.app.PendingIntent;
import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProvider;
import android.content.Context;
import android.content.Intent;
import android.widget.RemoteViews;

public class WidgetProvider extends AppWidgetProvider {

    @Override
    public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
        final int N = appWidgetIds.length;

        for (int i = 0; i < N; i++) {
            int widgetId = appWidgetIds[i];

            DBAdapter info = new DBAdapter(context);

            info.open();
            String data = info.getTextViewData();
            info.close();

            Intent intent = new Intent(context, Main.class);
            PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);

            RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget);
            views.setOnClickPendingIntent(R.id.loWidget, pendingIntent);
            views.setTextViewText(R.id.txtView, data);
            appWidgetManager.updateAppWidget(widgetId, views);
        }
    }
}

res – widget.xml:

<?xml version="1.0" encoding="utf-8"?>
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
    android:initialLayout="@layout/widget"
    android:minWidth="294dp"
    android:minHeight="72dp"
    android:updatePeriodMillis="1800000">
</appwidget-provider>

layout – widget.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/loWidget"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" 
    android:gravity="center"
    android:layout_margin="1dp"
    android:background="@drawable/background">

    <TextView
        android:id="@+id/txtView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="22dp"
        android:textColor="#ffffff"
        android:text="" />
</LinearLayout>

background.xml:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <gradient android:startColor="#CC111111" android:endColor="#CC111111" android:angle="0" />
    <padding android:left="4dp" android:top="1dp" android:right="4dp" android:bottom="1dp" />
    <corners android:radius="3dp" />
</shape>

getTextViewData() from DBAdapter.java:

public String getTextViewData() {
    String[] columns = new String[] { KEY_NAME };
    Cursor c = ourDatabase.query(DATABASE_TABLE, columns, null, null, null, null, null);

    String result = "";

    for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()) {           
        if (result.length() > 0) {
            result += ", ";
        }

        result += c.getString(0);
    }

    return result;
}

Anyone have a clue what’s missing in my code?

  • 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-14T15:05:15+00:00Added an answer on June 14, 2026 at 3:05 pm

    You need to set an update interval in milliseconds inside your Widget provider XML. Example code:

    <appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
        android:minWidth="294dp"
        android:minHeight="72dp"
        android:updatePeriodMillis="86400000"
        android:previewImage="@drawable/preview"
        android:initialLayout="@layout/example_appwidget"
        android:configure="com.example.android.ExampleAppWidgetConfigure" 
        android:resizeMode="horizontal|vertical"
        android:widgetCategory="home_screen|keyguard"
        android:initialKeyguardLayout="@layout/example_keyguard">
    </appwidget-provider>
    

    However, you should know that the system does not guarantee the widget to be updated as often. Also, if you want the widget to update more often (e.g. after a configuration change, as it is with your question), you need to do it manually. Here’s how I proceed:

    In this example my Widget class is simply called Widget.class:

    public class Widget extends AppWidgetProvider {
    
        // TODO: Don't forget to override the onUpdate method also
    
        @Override
        public void onReceive(Context context, Intent intent) {
            if (intent.getAction().equals("update_widget")) {
                // Manual or automatic widget update started
    
                RemoteViews remoteViews = new RemoteViews(context.getPackageName(),
                        R.layout.widget);
    
                // Update text, images, whatever - here
                remoteViews.setTextViewText(R.id.yourTextID, "My updated text");
    
                // Trigger widget layout update
                AppWidgetManager.getInstance(context).updateAppWidget(
                        new ComponentName(context, Widget.class), remoteViews);
            }
        }
    
    }
    

    Make sure to replace the layout and the TextView with references to your widget layout.

    Then whenever you want to update your widget (e.g. in the onPause method of your main activity or whenever a Save button is clicked), you call a PendingIntent:

    Intent updateWidget = new Intent(context, Widget.class); // Widget.class is your widget class
    updateWidget.setAction("update_widget");
    PendingIntent pending = PendingIntent.getBroadcast(context, 0, updateWidget, PendingIntent.FLAG_CANCEL_CURRENT);
    pending.send();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have defined the TextView array as final. And I set a OnClickListener() for
i want to set textview text in alertbox. I want to make the countdown
Whenever I add an EditText widget to the layout of my home screen widget
I have an app with a widget but I am having some difficulty with
I've created an app, a quite complex one. The main class is a tabhost
I have created a widget for my app. Everything works fine, but the only
My page loads a TextView which is scrollable. Unfortunately the position appears to stick
I have a multiline TextView in Android. It is a child of a LinearLayout.
I have a TextView that displays an error message in the login page of
I have textView in my cell and sometimes during tableView scroll some weird calls

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.