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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:59:40+00:00 2026-05-26T07:59:40+00:00

My widget has a service attached to it to process various click commands which

  • 0

My widget has a service attached to it to process various click “commands” which are passed through its intent. I’ve also set return START_REDELIVER_INTENT; for the case of when the service is restarted to not give a nullPointerException when calling intent.getAction(); and the like. The problem is, when the last intent was sent by one of the setOnClickPendingIntent calls I have, then when the service is restarted, it acts as if the user had clicked one of the viewId’s. e.g.

String command = intent.getAction();
int appWidgetId = intent.getExtras().getInt(AppWidgetManager.EXTRA_APPWIDGET_ID);
if(command.equals("some command")){
    //do something
}

...

remoteView.setOnClickPendingIntent(R.id.viewId,MyClass.makeControlPendingIntent(getApplicationContext(),"some command",appWidgetId));

Where makeControlPendingIntent is:

public static PendingIntent makeControlPendingIntent(Context context, String command, int appWidgetId) {
        Intent active = new Intent(context,MyService.class);
        active.setAction(command);
        active.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
        Uri data = Uri.withAppendedPath(Uri.parse("myclass://widget/id/#"+command+appWidgetId), String.valueOf(appWidgetId));
        active.setData(data);
        return(PendingIntent.getService(context, 0, active, PendingIntent.FLAG_UPDATE_CURRENT));
    }

Is there something I can do to check if the service is being restarted so as to not run any of those commands in the case where Android restarts my service?

  • 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-26T07:59:41+00:00Added an answer on May 26, 2026 at 7:59 am

    Is there something I can do to check if the service is being restarted so as to not run any of those commands in the case where Android restarts my service?

    The flags parameter to onStartCommand() will contain START_FLAG_REDELIVERY if the Intent is being re-delivered. So, you can do something like this:

    public int onStartCommand(Intent intent, int flags, int startId) {
        if ((flags & START_FLAG_REDELIVERY)!=0) { // if crash restart...
            // do something here
        }
    
        // rest of logic here
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've an application that has a widget already and have a service which updates
Slashdot has a little widget that allows you to tweak your comment threshold to
The organization I work for has created a small flash widget that we're encouraging
I'm trying to create a form that has an expandable widget. The problem is
How do I know when the date has been changed in a DatePicker widget?
Im using an existing widget from the jquery-ui labs call selectmenu. It has callback
Getting a rendering error for this form: 'NoneType' object has no attribute 'widget' http://dpaste.com/88585/
I have a widget that has a refresh button and a textview. Refresh updates
I've a django application, served via Twisted, which also serves ohter services (three sockets,
The TabHost widget has a setOnTabChangedListener() method to run code when the tab changes,

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.