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

  • Home
  • SEARCH
  • 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 6869395
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:33:08+00:00 2026-05-27T03:33:08+00:00

I just started to learn Android and I wrote the following code followed a

  • 0

I just started to learn Android and I wrote the following code followed a tutorial.

This is updating the textarea if click on it, but I would like to update in each 30 seconds. How can I do that?

I would like to measure my pulse and sending the data through Bluetooth. If my pulse is to high than the widget is warning me(Sound). What is the best way to manage this, I would like to check this in each 15 seconds. What is the most efficient way?

package com.test;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

import com.test.R;

import android.app.PendingIntent;
import android.app.Service;
import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProvider;
import android.content.Context;
import android.content.Intent;
import android.os.IBinder;
import android.util.Log;
import android.widget.RemoteViews;
import android.widget.Toast;

public class WidgetActivity extends AppWidgetProvider {
    public static WidgetActivity Widgetke = null;
    public static Context context;
    public static AppWidgetManager appWidgetManager;
    public static int appWidgetIds[];   

    @Override
    public void onUpdate( Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds )    {     
        if (null == context) context = WidgetActivity.context;
        if (null == appWidgetManager) appWidgetManager = WidgetActivity.appWidgetManager;
        if (null == appWidgetIds) appWidgetIds = WidgetActivity.appWidgetIds;

        WidgetActivity.Widgetke = this;
        WidgetActivity.context = context;
        WidgetActivity.appWidgetManager = appWidgetManager;
        WidgetActivity.appWidgetIds = appWidgetIds;

        Log.i("PXR", "onUpdate");

        final int N = appWidgetIds.length;
        for (int i=0; i<N; i++) {
            int appWidgetId = appWidgetIds[i];  

            updateAppWidget(context,appWidgetManager, appWidgetId);            
        }

    }


    static void updateAppWidget(Context context, AppWidgetManager appWidgetManager,
            int appWidgetId) {

        DateFormat format = SimpleDateFormat.getTimeInstance( SimpleDateFormat.MEDIUM, Locale.getDefault() );
        CharSequence text = "Time: " + format.format( new Date());

        Intent intent = new Intent(context, UpdateService.class);
        PendingIntent pendingIntent = PendingIntent.getService(context, 0, intent, 0);

        RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget);
        remoteViews.setOnClickPendingIntent(R.id.mainlayout, pendingIntent);

        remoteViews.setTextViewText(R.id.test_out, text);

        // Tell the widget manager
        appWidgetManager.updateAppWidget(appWidgetId, remoteViews);
    }

    public static class UpdateService extends Service {
        @Override
        public void onStart(Intent intent, int startId) {
            WidgetActivity.Widgetke.onUpdate(context, appWidgetManager, appWidgetIds);
            Toast.makeText(context, "Update Widget", Toast.LENGTH_SHORT).show();
        }

        @Override
        public IBinder onBind(Intent arg0) {
            return null;
        }
    }

}
  • 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-27T03:33:09+00:00Added an answer on May 27, 2026 at 3:33 am

    You can start up a new thread and use a for(;;) loop with a sleep. You can update the UI using a Handler (android.os.Handler) from there: http://www.mopri.de/2010/timertask-bad-do-it-the-android-way-use-a-handler/

    Alternatively, use a timer.

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

Sidebar

Related Questions

I just started to learn Android, I'm trying to write a widget which is
I just started to learn Android development. My previous experience is majorly .NET framework
I just started to learn jQuery and I came across this site- TEDx Portland
I've just started to learn about Asp.Net 3.5 compilation model, but most articles mostly
I'm just starting to learn Android development and writing my first app. I started
I have just started to learn ASP.NET MVC 3 form this book and I
i just started to learn coffeescript and it's great, but it's tricky.. i try
I have just started to learn NHibernate, and are following tutorials. On my own
I just started to learn Ruby and as a .Net developer, I'm wondering if
I just started to learn how to use action listeners. To my understanding it

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.