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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T16:08:11+00:00 2026-05-28T16:08:11+00:00

I have a widget that has a refresh button and a textview. Refresh updates

  • 0

I have a widget that has a refresh button and a textview. Refresh updates the content and when user clicks on textview it starts a new activity.

Problem is it works fine for a few hours and then onclick and refresh button doesn’t do anything. Nothing is captured in logcat. Also If user deletes widget and put a new one it starts working for a few hours and then the same story :(…what am I doing wrong!

Broadcast receiver.

onUpdate

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

        long interval = getrefresInterval();

        final Intent intent = new Intent(context, UpdateService.class);
        final PendingIntent pending = PendingIntent.getService(context, 0, intent, 0);
        final AlarmManager alarm = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
        alarm.cancel(pending);

        alarm.setRepeating(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime(),interval, pending);


        // Build the intent to call the service
           RemoteViews remoteViews = new RemoteViews(context.getPackageName(),R.layout.widget);



        // To react to a click we have to use a pending intent as the
            // onClickListener is excecuted by the homescreen application
            Intent ClickIntent = new Intent(context.getApplicationContext(),widgetHadith.class);
            Intent UpdateIntent = new Intent(context.getApplicationContext(),UpdateService.class);

            PendingIntent pendingIntent = PendingIntent.getActivity(context.getApplicationContext(), 0, ClickIntent,
                    PendingIntent.FLAG_UPDATE_CURRENT);


            PendingIntent pendingIntentUpdate = PendingIntent.getService(context.getApplicationContext(), 0, UpdateIntent,
                    PendingIntent.FLAG_UPDATE_CURRENT); //use this to update text on widget. if use this put UpdateService.class to intent

            remoteViews.setOnClickPendingIntent(R.id.widget_textview, pendingIntent);
            remoteViews.setOnClickPendingIntent(R.id.widget_refresh, pendingIntentUpdate);

            // Finally update all widgets with the information about the click listener
            appWidgetManager.updateAppWidget(appWidgetIds, remoteViews);


            // Update the widgets via the service
            context.startService(intent);

    }

onReceive

public void onReceive(Context context, Intent intent) {

    // v1.5 fix that doesn't call onDelete Action
    final String action = intent.getAction();
    if (AppWidgetManager.ACTION_APPWIDGET_DELETED.equals(action)) {
        final int appWidgetId = intent.getExtras().getInt(
                AppWidgetManager.EXTRA_APPWIDGET_ID,
                AppWidgetManager.INVALID_APPWIDGET_ID);
        if (appWidgetId != AppWidgetManager.INVALID_APPWIDGET_ID) {
            this.onDeleted(context, new int[] { appWidgetId });
        }
    } else {
        super.onReceive(context, intent);
    }
}

onDelete

public void onDeleted(Context context, int[] appWidgetIds) {
    //  Toast.makeText(context, "onDelete", Toast.LENGTH_SHORT).show();
        super.onDeleted(context, appWidgetIds);
    }

Service onstart where I am updating

    @Override
    public void onStart(Intent intent, int startId) {
        RemoteViews updateViews = new RemoteViews(this.getPackageName(),R.layout.widget);


        processDatabase();
        Spanned text = LoadHadith();
        String hadith = text.toString();
        Log.d("BR", "service---> ");
        // set the text of component TextView with id 'message'
        updateViews.setTextViewText(R.id.widget_textview, text);


        //Push update for this widget to the home screen
        ComponentName thisWidget = new ComponentName(this, HelloWidget.class);
        AppWidgetManager manager = AppWidgetManager.getInstance(this);
        manager.updateAppWidget(thisWidget, updateViews);
 }
  • 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-28T16:08:12+00:00Added an answer on May 28, 2026 at 4:08 pm

    The problem is that you can’t do a partiall update for a widget, you must set all the widget features, such as the set of PendingIntent’s every time you push a new remoteView.
    (Partiall updates are only available for API14 and up…).

    The reason your widgets are loosing their pendingIntents is that the android system saves the remoteView, and rebuilds your widget with it, in case it resets the widget (shortage of memmory, TaskManager/taskKiller in use, etc…), so you must set all the update code for the widget in the remoteView in your updateService.
    Otherwise, it’s just won’t set the pendingIntents again.

    So just add the code setting the pendingIntents to the service and your problem will be solved =]

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an Android widget that has a configure activity. I also have an
I have an activity that has a VideoView widget that plays a mp4 file,
I have a widget that supposed to call an Activity of the main app
My friend has a search engine that he wants to have a widget access
I have a page that has a bunch of widgets on it. Each widget
I have ASP.NET MVC application that has list with jQuery Selectable list. My problem
I have a sidebar widget that has an image background. Over this is a
I'm making a program that will have a widget that has to be fixed
Hi all I have a 'widget' table that has the following columns: widget, action,
I have an Activity that, for each widget in the layout, I call setOnClickListener()

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.