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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T18:33:13+00:00 2026-06-04T18:33:13+00:00

The following code have to start Alarming after 10000 ms from setting the time

  • 0

The following code have to start Alarming after 10000 ms from setting the time (clicking the button) .. but the AlarmManager starts the service immediately after clicking the button why ?
package pit.opensource.notificationapp;

import java.util.Calendar;

import android.app.Activity;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

public class NotificationAppActivity extends Activity {

    private PendingIntent pendingIntent;

    /** Called when the activity is first created. */

    @Override

    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.main);

        Button buttonStart = (Button)findViewById(R.id.btnset);

        buttonStart.setOnClickListener(new Button.OnClickListener(){

            @Override

            public void onClick(View arg0) {

                setAlarm();
                //setAlarm(25);

            }});

    }

    void setAlarm(){

        Intent myIntent = new Intent(NotificationAppActivity.this, ShowNotification.class);
        AlarmManager alarmManager = (AlarmManager)getSystemService(ALARM_SERVICE);

        alarmManager.cancel(pendingIntent);

        pendingIntent = PendingIntent.getService(NotificationAppActivity.this, 445454, myIntent, 0);



        //alarmManager.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis()-cal2.getTimeInMillis(), pendingIntent);
        alarmManager.set(AlarmManager.RTC_WAKEUP, 10000, pendingIntent);


    }

}

ShowNotification service

package pit.opensource.notificationapp;
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.util.Log;
import android.widget.Toast;

public class ShowNotification extends Service {

    @Override
    public void onCreate() {
        // TODO Auto-generated method stub
    }
    @Override
    public IBinder onBind(Intent intent) {
        // TODO Auto-generated method stub
        return null;
    }
    @Override
    public void onDestroy() {
        // TODO Auto-generated method stub
        super.onDestroy();
        Toast.makeText(this, "MyAlarmService.onDestroy()", Toast.LENGTH_LONG).show();
    }
    @Override
    public void onStart(Intent intent, int startId) {
        // TODO Auto-generated method stub
        super.onStart(intent, startId);
        Toast.makeText(this, "Alaaaaaaaaaarm ", Toast.LENGTH_LONG).show();
        Log.d("Aalram","Alaaaaaaaaaarm");

    }

}
  • 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-04T18:33:15+00:00Added an answer on June 4, 2026 at 6:33 pm

    The second parameter is not the delay relative to now, but the time the alarm should go off. Use something like System.currentTimeMillis() + 10000. It goes off right away because you are passing a start time in the past.

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

Sidebar

Related Questions

I have the following code that runs whenever you click the Start button on
I have the following code in my smarty template: {foreach from=$categories item=l} <tr>----------START---------------</tr> <br/>
I have code following lines to start multiple downloads from my application. The problem
I have the following code TransitionManager.start(babyPreloader,{type:Fade, direction:Transition.OUT, duration:0.5, easing:Regular.easeOut}); var tempPreloader:DisplayObject = babyPreloader as
I have the following code: //------------------------------------------------------// // When the document is ready, start firing
I have a header.html which start with session_start();. Then the following code, $_SESSION['cart'][$sw_id] is
Suppose I have a line of code that starts like the following: Func1(Func2(Func3 Is
I have the following code to start my own Cocoa HTTP Server . In
I have the following code: new Thread(new ThreadStart(delegate() { // something short })).Start(); Can
All, I have the following code: $fetch = mysql_query(SELECT * FROM calendar_events where event_status='booked'

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.