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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T13:04:50+00:00 2026-06-13T13:04:50+00:00

Why does my Android time widget doesn’t update on its own? I created a

  • 0

Why does my Android time widget doesn’t update on its own?
I created a time & date widgets for home screen but the problem is that my time widget is only updated if the screen orientation is changed for example from landscape to portrait.. It should be auto updated in real time mode.. Here’s my code:

public class PointlessWidget extends AppWidgetProvider {
    Time mCalendar;
    float mMinutes;
    float mHour;

    @Override
    public void onUpdate(Context context, AppWidgetManager appWidgetManager,
            int[] appWidgetIds) {
        // TODO Auto-generated method stub
        super.onUpdate(context, appWidgetManager, appWidgetIds);

        mCalendar = new Time();

        // Line below sets time that will be displayed - modify if needed.
        mCalendar.setToNow();


        int hour = mCalendar.hour;
        int minute = mCalendar.minute;
        int second = mCalendar.second;

        mMinutes = minute + second / 60.0f;
        mHour = hour + minute / 60.0f;

        final int N = appWidgetIds.length;

        for (int i = 0; i < N; i++) {
            int awID = appWidgetIds[i];
            RemoteViews v = new RemoteViews(context.getPackageName(),
                    R.layout.widget);

            v.setTextViewText(R.id.textHour, " " + hour);
            v.setTextViewText(R.id.textMinute, " " + minute);

            appWidgetManager.updateAppWidget(awID, v);
        }
    }

     @Override
     public void onDeleted(Context context, int[] appWidgetIds) {
     // TODO Auto-generated method stub
     super.onDeleted(context, appWidgetIds);

     Toast.makeText(context, "Widget Deleted!", Toast.LENGTH_SHORT).show();
     }

}

And here is my manifest:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.androidwidgets"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="11"
        android:targetSdkVersion="15" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >

        <receiver android:name=".PointlessWidget" >
            <intent-filter>
                <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
            </intent-filter>

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

        <activity android:name=".WidgetsConfig" >
            <intent-filter>
                <action android:name="android.appwidget.action.APPWIDGET_CONFIGURE" />
            </intent-filter>
        </activity>
    </application>

</manifest>

And this is my widget_stuff xml. I already set the updatePeriodMillis=”1000″ or equivalent to 1 sec in conversion.

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

</appwidget-provider>
  • 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-13T13:04:51+00:00Added an answer on June 13, 2026 at 1:04 pm

    I already figured out the solution in my problem.. And for the sake of others with the same problem as mine I will share my codes:

    import java.text.SimpleDateFormat;
    import java.util.Calendar;
    
    import android.os.Bundle;
    import android.os.Handler;
    import android.widget.TextView;
    import android.widget.Toast;
    import android.app.Activity;
    
    public class DigitalClock extends Activity {
        private Runnable updateTimeTask;
        private Handler handler;
    
        public static final int TIME_UPDATE_INTERVAL_MSEC = 1000;
    
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
    
            if (updateTimeTask == null) {
                updateTimeTask = new Runnable() {
                    @Override
                    public void run() {
                        // if (!DigitalClock.this.isActive()) return;
    
                        timeAndDate();
                        handler.postDelayed(this, TIME_UPDATE_INTERVAL_MSEC);
                    }
                };
            }
            if (handler == null) {
                handler = new Handler();
            }
            handler.removeCallbacks(updateTimeTask);
            handler.postDelayed(updateTimeTask, TIME_UPDATE_INTERVAL_MSEC);
        }
    
        public void timeAndDate() {
            Calendar c = Calendar.getInstance();
    
            SimpleDateFormat time = new SimpleDateFormat("hh:mm:ss");
            SimpleDateFormat date = new SimpleDateFormat("MMMM dd yyyy");
            SimpleDateFormat day = new SimpleDateFormat("EEEE");
            SimpleDateFormat am_pm = new SimpleDateFormat("aa");
            String sTime = time.format(c.getTime());
            String sDate = date.format(c.getTime());
            String sDay = day.format(c.getTime());
            String sAm_Pm = am_pm.format(c.getTime());
    
            // formattedDate have current date/time
            Toast.makeText(this, sDate + " | " + sTime, Toast.LENGTH_SHORT).show();
    
            // Now we display value in TextView
            TextView txtTime = (TextView) findViewById(R.id.txtHour);
            TextView txtDay = (TextView) findViewById(R.id.txtDay);
            TextView txtDate = (TextView) findViewById(R.id.txtDate);
            TextView txtAm_Pm = (TextView) findViewById(R.id.txtAm_Pm);
    
            txtTime.setText(sTime);
            txtDate.setText(sDate);
            txtDay.setText(sDay);
            txtAm_Pm.setText(sAm_Pm);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

does Android have a best practices guideline on creating & populating the db/tables programmatically
I'm having the hardest time figuring out how to remove home screen AppWidget's programmatically
The Android GenieWidget (also known as News & Weather Widget) updates very often (every
I have an android widget which is updated 1 time per day (as stated
Does Android support virtual memory concept? I read it does use paging but not
Does Android support pthreads? And why when i use -pthread option i see the
Does Android emulator support OpenGl ES2.0? I run the code but Eclipse gives me
Does android supports log2 ? I already find that android doesnt support long double.
Does android expose an API or somesuch for the development of thirdparty keyboard applications?
Does Android broadcast an intent when the network state has changend, i.e. from GSM

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.