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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T14:08:35+00:00 2026-06-17T14:08:35+00:00

I asked a question similar to this yesterday but have changed my code a

  • 0

I asked a question similar to this yesterday but have changed my code a fair bit and have a different issue now.

I have a toggle button that sets an alarm manager with a pending intent that should trigger after 5 seconds. I have it on a one shot setting, so i want the message to appear once (as later I will be implementing this for a date value).

I get no errors with this code, but I cant seem to trigger my intent that then shows my toast message.

Here’s how I have defined the activity of the ‘DateAlarm’ class in the xml:

     <activity
        android:name=".DateAlarm"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="com.example.flybase2.DateAlarm" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>

Heres my my toggle button onClick method for my toggle button with the alarm manager:

case (R.id.toggleButton1):

    Integer dobMonth = setDate.getMonth();
    Integer dobYear = setDate.getYear();
    Integer dobDate = setDate.getDayOfMonth();

    Date set;
    set = new Date(dobYear - 1900, dobMonth, dobDate);


    AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
    Intent intent = new Intent(this, DateAlarm.class);
    PendingIntent pendingIntent = PendingIntent.getService(this, 0, intent, PendingIntent.FLAG_ONE_SHOT);
    am.set(AlarmManager.RTC_WAKEUP,System.currentTimeMillis() + (5 * 1000), pendingIntent); 


    break;

And my final ‘DateAlarm’ class that holds the action of the intent.

package com.example.flybase2;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.widget.Toast;

public class DateAlarm extends Activity {

Context context;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

     Toast.makeText(context, "Appointment is today", Toast.LENGTH_LONG).show();
}

}

  • 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-17T14:08:36+00:00Added an answer on June 17, 2026 at 2:08 pm

    You have two problems:

    1. You are using PendingIntent.getService() instead of PendingIntent.getActivity() Since DateAlarm extends Activity, you want PendingIntent.getActivity().

    2. In DateAlarm your context variable is null. In onCreate() you should initialize it. Also note that since Activity extends Context, this variable isn’t needed. However if you do want to use that variable do:

    super.onCreate(savedInstanceState);
    context = this;
    

    or

    Context context = this; //right from the global declaration
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I already asked a similar question but this one is a bit different/specific: I'm
I have asked a question similar to this in the past but this is
I asked a similar question like this yesterday but after waiting for ever I
I've already asked similar question on this issue on stack overflow already, but I
I have asked a similar question like this before but I am going to
Ok, I have previously asked a similar question to this but it was voted
I asked a similar question yesterday, but have acquired a really odd problem since
This is similar to a question I asked yesterday but more specific to the
I had asked a question similar to this before, but I have a new
I asked a similar question yesterday that was specific to a technology, but now

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.