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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:38:39+00:00 2026-06-13T08:38:39+00:00

I have read most posts re this issue, but still can’t get my implementation

  • 0

I have read most posts re this issue, but still can’t get my implementation working, can you please help?

Basically I want to initiate a BroadcastReceiver from within an Activity, to do something every 10 seconds. So I set the Alarm, but the code never actually reaches “onReceive()”… I can’t spot any difference in my code from other examples, could you please take a look?

Also just to mention that I haven’t put a receiver in the manifest file, as I understand that it is not needed since I register it within the activity.

Thank you!

package alarm.in;

import alarm.in.activity.R;
import android.app.Activity;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.os.PowerManager;
import android.util.Log;
import android.view.View;
import android.widget.TextView;

public class activityActivity extends Activity {

    private Alarm alarm;  


    private static final String TAG = "AlarmInActivity";
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        alarm = new Alarm();           
    }


    public void onResume() {
        super.onResume();
        IntentFilter filter = new IntentFilter();
        filter.addAction(ALARM_SERVICE);
        registerReceiver(alarm, filter);
    }

    public void onPause() {
        super.onPause();
        this.unregisterReceiver(alarm);
    }

    public void setAlarm(View view){
        alarm.SetAlarm(getBaseContext(),1,10);             
    }

    public void cancelAlarm(View view){     
        alarm.CancelAlarm(getBaseContext());                    
    }


    private class Alarm extends BroadcastReceiver {
        @Override
        public void onReceive(Context context, Intent intent) {
            PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
            PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "");
            wl.acquire();

            Log.d(TAG, "Alarm Worked!");     
            wl.release();
        }

        public void SetAlarm(Context context, int minutes, int seconds)
         {
             AlarmManager am=(AlarmManager)context.getSystemService(ALARM_SERVICE);

             Intent i = new Intent(context, Alarm.class);
             PendingIntent pi = PendingIntent.getBroadcast(context, 0, i, 0);
             am.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), 1000 * seconds * minutes, pi); // Millisec * Second * Minute
             Log.d(TAG, "AlarmSet");         
         }

         public void CancelAlarm(Context context)
         {
             Intent intent = new Intent(context, Alarm.class);
             PendingIntent sender = PendingIntent.getBroadcast(context, 0, intent, 0);
             AlarmManager alarmManager = (AlarmManager) context.getSystemService(ALARM_SERVICE);
             alarmManager.cancel(sender);
             Log.d(TAG, "AlarmCancel");    
         }

    }


}
  • 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-13T08:38:40+00:00Added an answer on June 13, 2026 at 8:38 am

    You registered your receiver, but forgot to send the action to the receiver:

    Intent intent = new Intent(ALARM_SERVICE);
    sendBroadcast(intent);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have read most of the posts on here relating to this issue and
I have already read a lot of posts around this subject but I am
I've read most of the posts regarding this matter but I find nothing that
I have read many posts on this topic; among them and most recently .NET
Most posts I have read regarding implementation of copy constructor is that you must
I have read a couple of posts on this topic, but neither addresses my
I have read most of the WCF REST 404 posts but none that helped
I have read few articles about table partioning but still I am bit confused
I have read a bunch of forums on this but none have solved my
I have read most of the posts on here regarding floating point, and 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.