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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T08:04:26+00:00 2026-05-24T08:04:26+00:00

I have just started studying Android, I have limited java knowledge but am semi

  • 0

I have just started studying Android, I have limited java knowledge but am semi capable with c/c++ objective C etc… I am currently working through a p2pwrox ebook called Beginning Android Application Development that I brought, however I am coming unstuck with the “Try it out: Display Notifications on the status bar” on pg73.

I have managed to write it all out sweet and am getting used to the android sdk and eclipse ide, however I have got this error in my NotificationActivity.java file shown below that I just don’t know how to fix.

    package com.androidtestingfun.www;

import android.app.Activity;
import android.os.Bundle;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.view.View;
import android.widget.Button;

public class NotificationsActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        Button button = (Button) findViewById(R.id.btn_displaynotif);
        button.setOnClickListener(new Button.OnClickListener() {
            public void onClick(View v) {
                displayNotification();
            }
        });
    }

    protected void displayNotification()
    {
        //---PendingIntent to launch activity if the user selects this notification---
        Intent i = new Intent(this, NotificationView.class);
        i.putExtra("notificationID", notificationID); //-----the second parameter here is getting an error

        PendingIntent pendingIntent = 
                PendingIntent.getActivity(this, 0, i, 0);

        NotificationManager nm = (NotificationManager)
                getSystemService(NOTIFICATION_SERVICE);

        Notification notif = new Notification(
                R.drawable.icon,
                "Reminder: Meeting starts in 5 minutes",
                System.currentTimeMillis());

        CharSequence from = "System Alarm";
        CharSequence message = "Meeting with customer at 3pm...";

        notif.setLatestEventInfo(this, from, message, pendingIntent);

        //---100ms delay, vibrate for 250ms, pause for 100ms and then vibrate for 500ms---
        notif.vibrate = new long[] {100, 250, 100, 500};
        nm.notify(notificationID, notif);//-----the first parameter here is getting an error
    }
}

Any ideas that could hear me would be greatly appreciated, I have tried cleaning my build but that didnt do anything to help.

  • 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-05-24T08:04:27+00:00Added an answer on May 24, 2026 at 8:04 am

    You do not have a variable called notificationID.

    Add this variable to the class, see snippet example:

    public class NotificationsActivity extends Activity {
    
        private static final int notificationID = 1234;
    
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            // ........
        }
    
        protected void displayNotification()
        {
            //---PendingIntent to launch activity if the user selects this notification---
            Intent i = new Intent(this, NotificationView.class);
            i.putExtra("notificationID", notificationID); 
    
            PendingIntent pendingIntent = 
                    PendingIntent.getActivity(this, 0, i, 0);
    
            NotificationManager nm = (NotificationManager)
                    getSystemService(NOTIFICATION_SERVICE);
    
            Notification notif = new Notification(
                    R.drawable.icon,
                    "Reminder: Meeting starts in 5 minutes",
                    System.currentTimeMillis());
    
            CharSequence from = "System Alarm";
            CharSequence message = "Meeting with customer at 3pm...";
    
            notif.setLatestEventInfo(this, from, message, pendingIntent);
    
            notif.vibrate = new long[] {100, 250, 100, 500};
            nm.notify(notificationID, notif);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just started studying OOP and I am a little confused of the
I have just started using services in Android and I have a made a
I have just started programming in Objective-C, I understand it only partially supports method
I have just started working with with Styles and Control Templates and have created
i have just started programming for android and i have a little question i
I have just started working on WCF and I need to run a service
I have just started doing Android development on Mac OS X in Eclipse. When
Have just started using Google Chrome , and noticed in parts of our site,
Have just started using Visual Studio Professional's built-in unit testing features, which as I
Have just started playing with ASP.NET MVC and have stumbled over the following situation.

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.