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

The Archive Base Latest Questions

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

I want to invoke a method of an object from user defined class for

  • 0

I want to invoke a method of an object from user defined class for a particular interval of time for say 2 hours. The input parameter is a Context object.

I have used AlarmReceiver Broadcast Receiver which I registered in manifest

<receiver android:name=".AlarmReceiver" android:process=":remote"></receiver>

I am trying to start alarm manager through a Broadcast Receiver when a particular activity occurs. For receiving the alarm broadcasts I have created alarmReceiver. Do I need any kind of intent-filter for receiving alarm intents???

My problem is I want the application context inside alarmreceiver, I tried using the context of onReceive method of AlarmReceiver but it throws

    android.app.ReceiverRestrictedContext

error.

Any solution for this error? If needed I will publish my full code…

  • 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-27T13:11:09+00:00Added an answer on May 27, 2026 at 1:11 pm

    I use this code to activate periodic alarms via broadcast receiver:

    public class UpdateReceiver extends BroadcastReceiver {
    
        public static final String LOG_TAG = "camerawatch.alarmactivator";
        public static final String ACTION = "de.pribluda.android.camerawatch.UPDATE_ALARM";
    
        public static void activate(Context context) {
            AlarmManager alarmService = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
            Intent intent = new Intent(ACTION);
            PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_NO_CREATE);
            Log.d(LOG_TAG, "pending intent: " + pendingIntent);
            // if no intent there, schedule it ASAP
            if (pendingIntent == null) {
                pendingIntent = PendingIntent.getBroadcast(context, 0, intent, 0);
                // schedule new alarm in 15 minutes
                alarmService.setInexactRepeating(AlarmManager.RTC, System.currentTimeMillis(),300000, pendingIntent);
                Log.d(LOG_TAG, "scheduled intent: " + pendingIntent);
            }
        }
    
        @Override
        public void onReceive(Context context, Intent intent) {
            Log.d(LOG_TAG, "received intent: " + intent);
            CameraWidgetProvider.displayCurrentState(context);
        }
    }
    

    Note, that activation is done in static method, so I can call it from almost everywhere.
    I schedule alarm if and only there is no such pending intent. As for context – it is available virtually everywhere – In activity ( it is context itself ) in broadcast receiver (serice method parameter) etc.

    PS: broadcast receiver is preferable to service, because it does not run all the time. When service method returns, it is stopped and application is potentially disposed ( unles it does something else, but mostly it stays around in background). This provides better battery life

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

Sidebar

Related Questions

I want to invoke the main method which is static. I got the object
I want to specifically invoke the base class method; what's the most concise way
I want to invoke a selector of a method that has the usual NSError**
How can I invoke a method with parameters using reflection ? I want to
Simple problem (I think): I want to be able to invoke a click method
I want to create an instance of an IronPython class from C#, but my
In the viewController class I want to make a draw method that adds an
How would you invoke a client flash method from application server in java applicationadapter.
I just learned yesterday from this site that I can: class Seq(object): def __init__(self,
I want to do this: MethodInfo m = myList.GetType().GetMethod(ConvertAll, System.Reflection.BindingFlags.InvokeMethod).MakeGenericMethod(typeof(object)); List<object> myConvertedList = (List<object>)m.Invoke(myList,

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.