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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T21:22:26+00:00 2026-05-21T21:22:26+00:00

i have three classess.activity,service and appwidget. i have two buttons in appwidget. and onclicking

  • 0

i have three classess.activity,service and appwidget. i have two buttons in appwidget.
and onclicking of that button widget should be updated as well methods in my activity should be called, in my activity there are some buttons,when i click buttons in my activity widget should be updated.

In this some code is unused.

here is my code.

public class MediaAppWidgetProvider extends AppWidgetProvider {

    //update rate in milliseconds
    public static final int UPDATE_RATE = 1000;
    @Override
    public void onDeleted(Context context, int[] appWidgetIds) {
        for (int appWidgetId : appWidgetIds) {       
            setAlarm(context, appWidgetId, -1);
        }
        super.onDeleted(context, appWidgetIds);
    }

    @Override
    public void onDisabled(Context context) {
        context.stopService(new Intent(context,BackService.class));
        super.onDisabled(context);
    }

    @Override
    public void onUpdate(Context context, AppWidgetManager appWidgetManager,
            int[] appWidgetIds) {
        for (int appWidgetId : appWidgetIds) {
            setAlarm(context, appWidgetId, UPDATE_RATE);
        }
        super.onUpdate(context, appWidgetManager, appWidgetIds);
    }

    public static void setAlarm(Context context, int appWidgetId, int updateRate) {
        PendingIntent newPending = makeControlPendingIntent(context,BackService.UPDATE,appWidgetId);
        AlarmManager alarms = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
        if (updateRate >= 0) {
            alarms.setRepeating(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime(), updateRate, newPending);
        } else {
            // on a negative updateRate stop the refreshing 
            alarms.cancel(newPending);
        }
    }

    public static PendingIntent makeControlPendingIntent(Context context, String command, int appWidgetId) {
        Intent active = new Intent(context,BackService.class);
        active.setAction(command);
        active.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
        //this Uri data is to make the PendingIntent unique, so it wont be updated by FLAG_UPDATE_CURRENT
        //so if there are multiple widget instances they wont override each other
        Uri data = Uri.withAppendedPath(Uri.parse("MediaAppWidgetProvider://widget/id/#"+command+appWidgetId), String.valueOf(appWidgetId));
        active.setData(data);
        return(PendingIntent.getService(context, 0, active, PendingIntent.FLAG_UPDATE_CURRENT));
    }
}




public class BackService extends Service{

    public static final String UPDATE = "update";
    public static final String PLUS = "plus";
    public static final String MINUS = "minus";
    public static final long  MODIFY= 86400000;

    @Override
    public void onStart(Intent intent, int startId) {
        String command = intent.getAction();
        int appWidgetId = intent.getExtras().getInt(
                AppWidgetManager.EXTRA_APPWIDGET_ID);
        RemoteViews remoteView = new RemoteViews(getApplicationContext()
                .getPackageName(), R.layout.album_appwidget);
        AppWidgetManager appWidgetManager = AppWidgetManager
                .getInstance(getApplicationContext());
        SharedPreferences prefs = getApplicationContext().getSharedPreferences(
                "prefs", 0);


        //plus button pressed
        if(command.equals(PLUS)){
            SharedPreferences.Editor edit=prefs.edit();
            edit.putLong("goal" + appWidgetId,prefs.getLong("goal" + appWidgetId, 0)+MODIFY);
            edit.commit();

        //minus button pressed
        }else if(command.equals(MINUS)){
            SharedPreferences.Editor edit=prefs.edit();
            edit.putLong("goal" + appWidgetId,prefs.getLong("goal" + appWidgetId, 0)-MODIFY);
            edit.commit();
        }


        long goal = prefs.getLong("goal" + appWidgetId, 0);
        //compute the time left
        long left = goal - new Date().getTime();
        int days = (int) Math.floor(left / (long) (60 * 60 * 24 * 1000));
        left = left - days * (long) (60 * 60 * 24 * 1000);
        int hours = (int) Math.floor(left / (60 * 60 * 1000));
        left = left - hours * (long) (60 * 60 * 1000);
        int mins = (int) Math.floor(left / (60 * 1000));
        left = left - mins * (long) (60 * 1000);
        int secs = (int) Math.floor(left / (1000));
        //put the text into the textView
        remoteView.setTextViewText(R.id.title, days + " days\n" + hours
                + " hours " + mins + " mins " + secs + " secs left");
        //set buttons
        remoteView.setOnClickPendingIntent(R.id.control_play,MediaAppWidgetProvider.makeControlPendingIntent(getApplicationContext(),PLUS,appWidgetId));
        remoteView.setOnClickPendingIntent(R.id.control_next,MediaAppWidgetProvider.makeControlPendingIntent(getApplicationContext(),MINUS,appWidgetId));
        // apply changes to widget
        appWidgetManager.updateAppWidget(appWidgetId, remoteView);
        super.onStart(intent, startId);
    }
    @Override
    public IBinder onBind(Intent arg0) {
        return null;
    }

}

and here is my oncreate method code.

  Intent launchIntent = getIntent();
        Bundle extras = launchIntent.getExtras();
        appWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID,
                AppWidgetManager.INVALID_APPWIDGET_ID);

        // set the result for cancel first
        Intent cancelResultValue = new Intent();
        cancelResultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID,
                appWidgetId);
        setResult(RESULT_CANCELED, cancelResultValue);

        SharedPreferences prefs = self.getSharedPreferences("prefs", 0);
        SharedPreferences.Editor edit = prefs.edit();
        edit.putLong("goal" + appWidgetId, 0l);
        edit.commit();
        // fire an update to display initial state of the widget
        PendingIntent updatepending = MediaAppWidgetProvider
                .makeControlPendingIntent(self,
                        BackService.UPDATE, appWidgetId);
        try {
            updatepending.send();
        } catch (CanceledException e) {
            e.printStackTrace();
        }
        // change the result to OK
        Intent resultValue = new Intent();
        resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID,
                appWidgetId);
        setResult(RESULT_OK, resultValue);

my question:
1.why i am getting this error “unable to start service intent”
2.i simply want to update widget when in my activity button is clicked and when i click on widget buttons widget should be updated and method should be called from service class.

here is my log.

ain/com.streamingmusic.widget.BackService (has extras) }: not found
W/AudioFlinger(   31): write blocked for 91 msecs
W/AudioFlinger(   31): write blocked for 66 msecs
W/AudioFlinger(   31): write blocked for 95 msecs
W/AudioFlinger(   31): write blocked for 67 msecs
D/PlayerDriver(   31): buffering (96)
W/AudioFlinger(   31): write blocked for 90 msecs
W/AudioFlinger(   31): write blocked for 69 msecs
W/AudioFlinger(   31): write blocked for 101 msecs
W/AudioFlinger(   31): write blocked for 79 msecs
W/AudioFlinger(   31): write blocked for 82 msecs
W/ActivityManager(   52): Unable to start service Intent { act=update dat=MediaAppWidgetProvider://widget/id/25#update25 flg=0x4 cmp=org.streamingmusic.m
ain/com.streamingmusic.widget.BackService (has extras) }: not found
W/AudioFlinger(   31): write blocked for 80 msecs
W/AudioFlinger(   31): write blocked for 66 msecs
W/AudioFlinger(   31): write blocked for 89 msecs
W/AudioFlinger(   31): write blocked for 67 msecs
W/AudioFlinger(   31): write blocked for 91 msecs
W/AudioFlinger(   31): write blocked for 68 msecs
W/AudioFlinger(   31): write blocked for 87 msecs
W/AudioFlinger(   31): write blocked for 70 msecs
D/PlayerDriver(   31): buffering (97)
W/AudioFlinger(   31): write blocked for 65 msecs
W/ActivityManager(   52): Unable to start service Intent { act=update dat=MediaAppWidgetProvider://widget/id/25#update25 flg=0x4 cmp=org.streamingmusic.m
ain/com.streamingmusic.widget.BackService (has extras) }: not found
W/AudioFlinger(   31): write blocked for 97 msecs
W/AudioFlinger(   31): write blocked for 70 msecs
W/AudioFlinger(   31): write blocked for 88 msecs
W/AudioFlinger(   31): write blocked for 68 msecs
W/AudioFlinger(   31): write blocked for 79 msecs
W/AudioFlinger(   31): write blocked for 79 msecs
W/AudioFlinger(   31): write blocked for 72 msecs
W/ActivityManager(   52): Unable to start service Intent { act=update dat=MediaAppWidgetProvider://widget/id/25#update25 flg=0x4 cmp=org.streamingmusic.m
ain/com.streamingmusic.widget.BackService (has extras) }: not found
W/AudioFlinger(   31): write blocked for 132 msecs
W/AudioFlinger(   31): write blocked for 89 msecs
W/AudioFlinger(   31): write blocked for 72 msecs
W/AudioFlinger(   31): write blocked for 77 msecs
D/PlayerDriver(   31): buffering (97)
W/AudioFlinger(   31): write blocked for 80 msecs
W/AudioFlinger(   31): write blocked for 87 msecs
W/AudioFlinger(   31): write blocked for 68 msecs
W/AudioFlinger(   31): write blocked for 92 msecs
W/AudioFlinger(   31): write blocked for 69 msecs
W/ActivityManager(   52): Unable to start service Intent { act=update dat=MediaAppWidgetProvider://widget/id/25#update25 flg=0x4 cmp=org.streamingmusic.m
ain/com.streamingmusic.widget.BackService (has extras) }: not found
W/AudioFlinger(   31): write blocked for 93 msecs
W/AudioFlinger(   31): write blocked for 66 msecs
W/AudioFlinger(   31): write blocked for 86 msecs
W/AudioFlinger(   31): write blocked for 73 msecs
W/AudioFlinger(   31): write blocked for 72 msecs
W/AudioFlinger(   31): write blocked for 88 msecs
W/AudioFlinger(   31): write blocked for 68 msecs
W/AudioFlinger(   31): write blocked for 96 msecs
W/AudioFlinger(   31): write blocked for 69 msecs
W/ActivityManager(   52): Unable to start service Intent { act=update dat=MediaAppWidgetProvider://widget/id/25#update25 flg=0x4 cmp=org.streamingmusic.m
ain/com.streamingmusic.widget.BackService (has extras) }: not found
W/AudioFlinger(   31): write blocked for 103 msecs
W/AudioFlinger(   31): write blocked for 83 msecs
W/AudioFlinger(   31): write blocked for 67 msecs
D/PlayerDriver(   31): buffering (97)
W/AudioFlinger(   31): write blocked for 90 msecs
W/AudioFlinger(   31): write blocked for 80 msecs
D/PlayerDriver(   31): buffering (98)
W/AudioFlinger(   31): write blocked for 72 msecs
W/AudioFlinger(   31): write blocked for 66 msecs
W/AudioFlinger(   31): write blocked for 90 msecs
W/ActivityManager(   52): Unable to start service Intent { act=update dat=MediaAppWidgetProvider://widget/id/25#update25 flg=0x4 cmp=org.streamingmusic.m
ain/com.streamingmusic.widget.BackService (has extras) }: not found
W/AudioFlinger(   31): write blocked for 93 msecs
W/AudioFlinger(   31): write blocked for 91 msecs
W/AudioFlinger(   31): write blocked for 68 msecs
W/AudioFlinger(   31): write blocked for 66 msecs
W/AudioFlinger(   31): write blocked for 96 msecs
W/AudioFlinger(   31): write blocked for 88 msecs

thankx

  • 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-21T21:22:27+00:00Added an answer on May 21, 2026 at 9:22 pm

    Take a look at http://programmerbruce.blogspot.com/2011/04/simple-complete-app-widget-part-1.html for a complete, working example of an App Widget successfully using intents to launch an activity and App Widget updates.

    If you’re still stuck, then it may help folks to help you, if you were to post complete minimal code – including all XML – to replicate your problem.

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

Sidebar

Related Questions

So, Here is my scenario: I have two activity and one service --> all
I have three classes that I am using and have shortened for ease of
I have three classes that all have a static function called 'create'. I would
Well I have a main Screen with 5 buttons. Each time a press a
I have an activity with three fragment classes inside it. I get an error
Would someone please provide me an example of the following Activity/Service/Application combination. I have
I have three class in my app. First extends Activity public class TestProjActivity extends
Have three classes User, Group and Field. Many to many relationship on User /
I have three classes: PurchaseOrder, PurchaseOrderLine, Item PurchaseOrder children are PurchaseOrderLine which is related
I have three classes, I am simply display my Facebook friends in tableView. And

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.