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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:12:03+00:00 2026-06-15T17:12:03+00:00

My friend and I are teaching ourselves android by programming a toy app, literally.

  • 0

My friend and I are teaching ourselves android by programming a toy app, literally. We made a simple game that uses the accelerometer. The game is just a maze game with a ball. We use the accelerometer to detect movement and use tile detections to determine whether the ball is on a path or hits a wall.

However, we want to build a timing service with the accelerometer as well. This timing service would determine when the user is being idle using the accelerometer (like 10 secs), issue a warning, then turn off the game. That is, kill the activity.

So what I am doing now is to see if I can throw up a message within 10 seconds of the game running on the widget. I am basing this exactly off the code found here:

I implemented the code found on that tutorial above as follows in my view below. I created a method called timingService and called it in my toyappView:

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

 // add 10 seconds to the calendar object
 cal.add(Calendar.SECOND, 10);
 Intent intent = new Intent(context, AlarmReciever.class);
 intent.putExtra("alarm_message", "This is the alarm message");

 // 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);


}

Here is the class it should be calling when the alarm goes off.

package com.example.toyapp;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.widget.Toast;



public class AlarmReciever extends BroadcastReceiver{

    @Override
    public void onReceive(Context context, Intent intent) {
        // TODO Auto-generated method stub
        try{
            Bundle bundle = intent.getExtras();
            String message = bundle.getString("alarm message");
            Toast.makeText(context, message, Toast.LENGTH_LONG).show();

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

    }

}

After here I just get stuck again. My AlarmReciever from the tutorial is never being called. Why? I ran debug with my emulator and it never goes into the AlarmReciever. As far as I am concerned, this game should go for 10 seconds and then call the AlarmReciever and display a message on my widgit. Right? I suspect my problem is in am.set? But I don’t see why.

As always, thank you all for your patience. I appreciate your comments and insights as I teach myself how to write a toy app in android. This may seem silly to others, but I already put a lot of thought in this. So I would appreciate any help others would have to offer. Hope you let me off on that technicality. Also, I have a cold. I don’t believe this duplicates other’s problems on stackoverflow as this alarm is going to be modified for a accelerometer. I will change it from making a toast message to killing the game.

Warm Regards,
GeekyOmega

PS – Some similar issues around, but found nothing that addressed why my class is not being called. I have a really bad cold too, so please let me off on that technicality. I’m trying. 🙂

  • 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-15T17:12:04+00:00Added an answer on June 15, 2026 at 5:12 pm

    I would recommend using the AlarmManager. Every time your onSensorChanged(…) gets called you reset an alarm that will end your game in 10 seconds.

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

Sidebar

Related Questions

Problem Description: My friend and I are teaching ourselves android development. We debugged the
a friend and I develop a web application for conferences management that uses hibernate
So I'm teaching a friends son some python programming, just going through control of
My friend gave me a database file: record.mdf . I copied that .mdf file
A friend of mine is making a trivia game in C++, and I am
I am teaching my friend how to make websites. I would like to keep
A friend and developer I respect recently advised that I avoid using 'Includes' in
A friend of mine just used plain-old cat to concatenate two mp3 files,... cat
My friend (who knows nothing about programming what-so-ever) asked me if I could develop
My friend read an article which mentioned that moving all JavaScript files to the

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.