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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T13:44:45+00:00 2026-06-12T13:44:45+00:00

I have the following in an activity, it basically sets an AlarmManager when the

  • 0

I have the following in an activity, it basically sets an AlarmManager when the user logs into the app. The AlarmManager then periodically calls another activity that deletes transactions from the phone’s DB. All this works fine.

// get a Calendar object with current time
Calendar cal = Calendar.getInstance();
// add 5 minutes to the calendar object
cal.add(Calendar.MINUTE, 1);
Intent intent = new Intent(EntryActivity.this, AlarmReceiver.class);
intent.putExtra("alarm_message", "deleting transactions");
// In reality, you would want to have a static variable for the request code instead of 192837
PendingIntent sender = PendingIntent.getBroadcast(EntryActivity.this, 192837,
                                    intent, PendingIntent.FLAG_UPDATE_CURRENT);
// Get the AlarmManager service
AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);
//am.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), sender);
am.setRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), 15000, sender);

.

public class AlarmReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        try {
            Bundle bundle = intent.getExtras();
            String message = bundle.getString("alarm_message");
            Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
            Intent myIntent = new Intent(context, SendOutstandingTransactions.class);
            myIntent.setAction("com.carefreegroup.startatboot.MyService");
            context.startService(myIntent);
        } catch (Exception e) {
            Toast.makeText(context, "There was an error somewhere, but we still"
                            + " received an alarm", Toast.LENGTH_SHORT).show();
            e.printStackTrace();
        }
    }
}

.

public class SendOutstandingTransactions extends IntentService {

    private static final String TAG = SendOutstandingTransactions.class.getSimpleName();
    NfcScannerApplication nfcscannerapplication;
    Cursor c;

    @Override
    public void onCreate() {
        nfcscannerapplication = (NfcScannerApplication)getApplication();
        super.onCreate();
    }

    @Override
    protected void onHandleIntent(Intent intent) {
        nfcscannerapplication.loginValidate.deleteTableTransactions();
    }

    public SendOutstandingTransactions() {
        super("SendOutstandingTransactions");
    }
}// end of class

The Service that deletes the transactions periodically is called only when the user first logs into app. It runs indefinitely from that point on. What if the user reboots the phone? The service will only resume the next time the user logs in.

I have a BootReceiver but i don’t know how to attach the AlarmManager. I’ve tried the following but ALARM_SERVICE cannot be resolved. Is this on the right lines?

public class MyBootReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {

        //  Intent myIntent = new Intent(context, SendOutstandingTransactions.class);
        //  myIntent.setAction("com.carefreegroup.startatboot.MyService");
        //  context.startService(myIntent);

        // get a Calendar object with current time
        Calendar cal = Calendar.getInstance();
        // add 5 minutes to the calendar object
        cal.add(Calendar.MINUTE, 1);
        Intent intent = new Intent(MyBootReceiver.this, AlarmReceiver.class);
        intent.putExtra("alarm_message", "deleting transactions");
        // In reality, you would want to have a static variable for the request code instead of 192837
        PendingIntent sender = PendingIntent.getBroadcast(context, 192837,
                                    intent, PendingIntent.FLAG_UPDATE_CURRENT);
        // Get the AlarmManager service
        AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);
        //am.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), sender);
        am.setRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), 15000, sender);
    }
}
  • 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-12T13:44:49+00:00Added an answer on June 12, 2026 at 1:44 pm

    getSystemService is available on a Context. (You receive it in the onReceive)

    You should do:

    AlarmManager am = (AlarmManager) context.getSystemService(context.ALARM_SERVICE);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following scenario: in activity A, when a user clicks a button,
I have the following problem: I have an Activity where a user can start
I have an broadcast-receiver that looks like the following within an activity named childActivity
I have an activity that appears as a dialog using the following custom theme:
I have following Test Android App. public class TestActivity extends Activity { @Override public
I have the following code in an Activity that starts a dialog for a
I have the following in my Activity that I use to download a users
I have following function in one Activity public void AppExit() { Editor edit =
In my android application, I have following requirement. Activity A --> Activity B(Go to
Within one Activity I have th following piece of code: public void onStartMonitoringToggleClicked(View v)

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.