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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T13:59:20+00:00 2026-06-15T13:59:20+00:00

I am almost finished with this game I have been making. It is a

  • 0

I am almost finished with this game I have been making. It is a toy app and is only serving to teach me. So I call it toyapp.

I am trying to use what I learned about alarmmanager, intent, and broadcast to kill my application. I figured out how to get my alarm to go 10 seconds and then print a message to a widget. This was based on the following tutorial here.

It was my thinking that I could just call this up, warn the user I am about to kill this application and then close it out. However, it appears that the AlarmReceiver is not being called at all? My game just keeps playing.

The code I have modified is below for my toyapp.

public void timingService(Context context, Activity activity){
    // get a Calendar object with current time
     Calendar cal = Calendar.getInstance();

 // add 5 minutes to the calendar object
 cal.add(Calendar.SECOND, 5);

 Intent intent = new Intent(context, AlarmReciever.class);
 intent.putExtra("alarm_message", "Game will exit soon");


 // 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) activity.getSystemService(context.ALARM_SERVICE);
 am.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), sender);

}

Now, put my Receiver code in my activity class. Which is as follows:

public class AlarmReciever 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_LONG).show(); //Give message
                toyappActivity.this.finish(); //Exit the game

            }catch(Exception e){
                Toast.makeText(context, "There was an error somewhere", Toast.LENGTH_LONG).show();
                e.printStackTrace();
            }

        }


    }//End of AlarmReciever

My inspiration for this approach was the following that I read here.

What I eventually want to do is simple. I will have an option to play the game with or without the alarm. I plan on reseting the alarmmanager with the accelerometer sensor if movement is detected. Otherwise, it will just countdown and then cancel the game.

I suspect I am not understanding intents directly, but this is my crashing point. I am so sorry if this seems stupid, but I have a rather bad cold right now and this seems like it should work to me. However, computers never lie, only our minds.

As always, you are all the best group of coders and developers. I learn so much from you all and your help is so much appreciated. Any dumb mistakes are my own, but I hope you let me off on that technicality.

Warm Regards,
GeekyOmega

  • 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-15T13:59:21+00:00Added an answer on June 15, 2026 at 1:59 pm

    The Alarm is set properly: am.set(...), it should be called only once.
    But you would expect a message on you screen with:

    Toast.makeText(context, message, Toast.LENGTH_LONG).show(); //Give message
    

    The proces will refer to a :remote not sure the context what will be, as I remmeber the appContext. It seems you are trying to show a message from background and your GUI may block it. Try to remove (comment) that maeesage and let the

    toyappActivity.this.finish(); //Exit the game
    

    code run, just do a Log.d() if you want.

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

Sidebar

Related Questions

I am almost finished with this toy app game I am making. Problem: My
I'm a little stuck. I have almost finished this code but after trying to
I have been almost finished (well i thought i finished) writing this login page
I am trying to make my own user control and have almost finished it,
I've almost finished my app. One of the views uses GLKit. I just have
I have almost finished my app for android, the problem is when i test
I have created a web app that is almost finished. I need it to
I am working on my classwork of the calculator. I have been almost finished.
I am almost finished with this flash game, but when I test it the
Thanks to this site and your help, I have almost finished my Googlemaps script.

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.