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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T15:57:00+00:00 2026-06-12T15:57:00+00:00

I have an IntentService that is initially started with the click on a button:

  • 0

I have an IntentService that is initially started with the click on a button:

        Intent intent = new Intent(this, ProximityService.class);
        intent.putExtra("com.hybris.proxi.triggerTime", 5000l);
        PendingIntent pendingIntent = PendingIntent.getService(this,  0,  intent, 0);
        long trigger = System.currentTimeMillis() + (5*1000);
        alarmManager.set(AlarmManager.RTC_WAKEUP, trigger, pendingIntent);

This works nicely. But then I am trying to execute the same intentservice again, from within the intentservice. The idea here is that I can vary the next execution time to save battery.

@Override
protected void onHandleIntent(Intent intent) {
    Log.d("demo", "ProximityService... STARTING");
    Log.d("demo", "Intent has extra with key com.hybris.proxi.triggerTime" + intent.hasExtra("com.hybris.proxi.triggerTime"));

    long lastTriggerTime = intent.getLongExtra("com.hybris.proxi.triggerTime", -1);
    Log.d("demo", "Last trigger time: " + lastTriggerTime);

    alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);

    //trigger me again - TODO change this based on closeness to store
    //TODO does not work, somehow triggertime is not incremented
    if (lastTriggerTime < 50000)
    {
        long newTriggerTime = lastTriggerTime * 2;

        Intent serviceIntent = new Intent(this, ProximityService.class);
        serviceIntent.putExtra("com.hybris.proxi.triggerTime", (long)newTriggerTime);
        Log.d("demo","New triggerTime set in new intent is : " + serviceIntent.getLongExtra("com.hybris.proxi.triggerTime", -1));

        PendingIntent pendingIntent = PendingIntent.getService(this,  0,  serviceIntent, 0);
        long trigger = System.currentTimeMillis() + newTriggerTime;
        alarmManager.set(AlarmManager.RTC_WAKEUP, trigger, pendingIntent);
        Log.d("demo", "Alarm was set with trigger time " + newTriggerTime);
    } 
    else {
        Log.d("demo", "Not rescheduling alarm: lastTriggerTime is " + lastTriggerTime);
    }


    Log.d("demo", "ProximityService... DONE");

}

The problem is that

intent.getLongExtra(“com.hybris.proxi.triggerTime”, -1);

always returns the initial value 5000 – so the next alarm is not scheduled at an inceasing trigger time. Somehow, the setting of the intent extra for the new trigger time does not work…

Any ideas?

  • 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-12T15:57:02+00:00Added an answer on June 12, 2026 at 3:57 pm

    You need to Use PendingIntent.FLAG_UPDATE_CURRENT

    Change your code from
    PendingIntent pendingIntent = PendingIntent.getService(this, 0, serviceIntent, 0);
    to

    PendingIntent pendingIntent = PendingIntent.getService(this,
                            0,  serviceIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I have the following code: Intent intent = new Intent(this,DownloadService.class); for(int i=0;i<filesArray.length;i++){ startService(intent);
I have class that extends 'IntentService' - this class occasionally receives data from a
i have this IntentService code which run a service once: protected void onHandleIntent(Intent intent)
i have an activity (ApplicationActivity) that call an intent service (DownloadService) The intentService download
I have an IntentService that is parsing some xlm file to create a html
have written this little class, which generates a UUID every time an object of
I have an IntentService that downloads some files. The problem is that I create
I have an Android IntentService that is behaving strangely. I am sending it an
I'm trying to understand the IntentService class so that I can build my own
I have this widget that toggles sound on off but instead of that 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.