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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T02:38:31+00:00 2026-06-15T02:38:31+00:00

I want to implement a CountDownTimer in a widget. What I came up with

  • 0

I want to implement a CountDownTimer in a widget. What I came up with is:

import android.content.Intent;
import android.os.CountDownTimer;
import android.widget.RemoteViews;
import android.widget.TextView;

public class CountDown extends CountDownTimer {
    private RemoteViews views;

    public CountDown(long millisInFuture, int countDownInterval, RemoteViews views) {
        super(millisInFuture, countDownInterval);

        this.views = views;
    }

    @Override
    public void onFinish() {
    }

    @Override
    public void onTick(long millisUntilFinished) {
        int days = (int) (millisUntilFinished / (1000 * 60 * 60 * 24));

            views.setTextViewText(R.id.countWidget, days);
    }
}

And the AppWidgetProvider class

import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;

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

public class CountDownWidgetProvider extends AppWidgetProvider {
    private Calendar currentDate = Calendar.getInstance();
    private Calendar firstDecember = Calendar.getInstance();

    public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
        Date date = new Date();

        this.firstDecember.setTimeZone(TimeZone.getTimeZone("Europe/Berlin"));
        this.currentDate.setTimeZone(TimeZone.getTimeZone("Europe/Berlin"));
        this.firstDecember.set(2012, 11, 1, 0, 0, 0); // TODO: Set to December
        this.currentDate.setTime(date);

        final int N = appWidgetIds.length;

        // Perform this loop procedure for each App Widget that belongs to this provider
        for (int i=0; i<N; i++) {
            int appWidgetId = appWidgetIds[i];

            // Create an Intent to launch MainActivity
            Intent intent = new Intent(context, MainActivity.class);
            PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);

            // Get the layout for the App Widget and attach an on-click listener
            // to the button
            RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.count_down_app_widget);
            views.setOnClickPendingIntent(R.id.countWidget, pendingIntent);

            long millis = this.firstDecember.getTimeInMillis() - this.currentDate.getTimeInMillis();

            CountDown countDown = new CountDown(millis, 1000, views);
            countDown.start();

            // Tell the AppWidgetManager to perform an update on the current app widget
            appWidgetManager.updateAppWidget(appWidgetId, views);
        }
    }
}

But it does not work that way. The widgets TextView does not refresh or even change. It seems like the CountDown does not start.

Maybe I made a mistake somewhere, but I’m new to android development, so I thought you could help me out.

  • 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-15T02:38:33+00:00Added an answer on June 15, 2026 at 2:38 am
    you have to update widget after setting the text
    use 
     appWidgetManager.updateAppWidget(appWidgetId, views);
    
    
     after
      views.setTextViewText(R.id.countWidget, days);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

given this class definition: public class Frame { IFrameStream CapturedFrom; } I want implement
We want to implement Public Transport Guide for Android. Inputs will be beginning and
I am using Android Timer for a game. I want to implement a countdown
I'm trying to implement a countdown timer into a pre-existing public class and I
I want to implement a generic class AppContextItem with the generic Interface IAppcontextItem. As
I want to implement a hash table in python. On the table a class
I wrote small service class and I want implement something like that : service
I want to implement a countdown timer using Reactive Cocoa in iOS. The timer
I am new to Graph concept in android. In my app i want implement
I want to implement in Java a class for handling graph data structures. I

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.