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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T05:26:59+00:00 2026-06-16T05:26:59+00:00

I have application, which makes event in alarm manager, and at specific time its

  • 0

I have application, which makes event in alarm manager, and at specific time its called.
Code looks like this

Intent intent = new Intent(this, AlarmActivity.class);
pendingIntent = PendingIntent.getActivity(this,req_code, intent, PendingIntent.FLAG_CANCEL_CURRENT);    
AlarmManager am = (AlarmManager)getSystemService(Activity.ALARM_SERVICE);
am.setRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(),AlarmManager.INTERVAL_DAY*7,
                    pendingIntent);

Intent calls this activity.

public class AlarmActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    public void onStart(){
        super.onStart();
        //Change ringer mode
        //Add notification in status bar
        //Other booring stuff here...
        Toast.makeText(this,"Finishing",2000).show();
        finish();
    }
}

in booring stuffthere are is code which should run in background (change ringermode)

Everything works for me, except one thing. Whenever the alarm manager calls my activity – the application comes to foreground.
When it only should change ringer mode in background, and add notification in status bar.

Any way to not allow application come to foreground?

  • 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-16T05:27:00+00:00Added an answer on June 16, 2026 at 5:27 am

    You should do all of this in a BroadCastReceiver. There is no UI, and there is a Context variable passed on to the Receiver’s onReceive() method which allows you to basically do anything the Activity does, without having an actual UI. This means that you can set the ringer, show the status bar notification, etc.
    Your BroadcastReceiver class should look something like:

    public class AlarmBroadcastReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        //Change ringer mode
        //Add notification in status bar
        //Other boring stuff here...
        Toast.makeText(context,"Finishing",2000).show();
        }
    }
    

    Note that for your Toast, the variable named context is used.

    And your AlarmManager code should look something like this:

    Intent intent = new Intent(this, AlarmBroadcastReceiver.class);
    pendingIntent = PendingIntent.getBroadcast(this,req_code, intent, PendingIntent.FLAG_CANCEL_CURRENT);    
    AlarmManager am = (AlarmManager)getSystemService(Activity.ALARM_SERVICE);
    am.setRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(),AlarmManager.INTERVAL_DAY*7,
                        pendingIntent);
    

    Your manifest should have this:

     <receiver android:name=".AlarmBroadcastReceiver" >
            </receiver>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have developed a C# application which makes heavy use of events. Now this
I have C# application that makes use of some C libaries(which I have written
I have application which uses Sherlock ActionBar package. The application uses platform-specific behavior for
I have an application which makes calls to an online database. If I lose
I have a .NET MVC application which makes extensive use of AJAX and modal
I have an Android application, which makes use of an AlarmManager to schedule events.
I have a Silverlight 4 application which talks to a 'manager' class, which talks
i have developed some applications for blind which makes them to use basic mobile
I just want to know that can i make an application which have some
I have a relatively simple application which I need to make native Mac OSX

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.