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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T17:10:43+00:00 2026-06-02T17:10:43+00:00

I referred following links to study the demo example on Notification service in Android

  • 0

I referred following links to study the demo example on Notification service in Android : Sai Geetha Blog and Vogella Tutorial.

Both worked but partially i.e. I’ve downloaded both projects as it is and executed them. Both has button to initiate the notification. On Button Click notification appears at the top status bar.

Here comes the problem, on click of that notification, neither any message is getting displayed nor intent is getting fired to navigate to new activity.

I’m new to this concept so any help appreciated…

EDIT

CreateNotification .class

public class CreateNotification extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }

    public void createNotification(View view) {
        NotificationManager nm= (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
        final int UNIQUE_ID = 123458;
        Intent navigationIntent = new Intent();
        navigationIntent.setClass(CreateNotification.this,
                NotificationReceiver.class);

        PendingIntent pi = PendingIntent.getActivity(this, 0, navigationIntent,
                0);
        String body = "New Notification added!!!";
        String title = "Title";
        Notification n = new Notification(R.drawable.ic_launcher, body,
                System.currentTimeMillis());
        n.number = 2;
        n.setLatestEventInfo(this, title, body, pi);
        n.defaults = Notification.DEFAULT_ALL;
        nm.notify(UNIQUE_ID, n);
    }
}

NotificationReceiver.class

public class NotificationReceiver extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.result);
        Log.i("Receiver", "NotificationReceiver");
    }
}

main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <Button
        android:id="@+id/button1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:onClick="createNotification"
        android:text="Create Notification" >
    </Button>

</LinearLayout>

result.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="This is the result activity opened from the notification" >
    </TextView>

</LinearLayout>
  • 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-02T17:10:44+00:00Added an answer on June 2, 2026 at 5:10 pm

    check this out

       public static NotificationManager nm;
    public static final int UNIQUE_ID = 123458;
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.newone);
        createNotification();
    
    }
    public void createNotification() {
        NotificationManager nm= (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
        final int UNIQUE_ID = 123458;
        Intent navigationIntent = new Intent();
        navigationIntent.setClass(NEWAct.this,
                TestActivity.class);
        navigationIntent.putExtra("selected_tab", "more");
    
        PendingIntent pi = PendingIntent.getActivity(this, 0, navigationIntent,
                0);
        String body = "New Notification added!!!";
        String title = "Title";
        Notification n = new Notification(R.drawable.ic_launcher, body,
                System.currentTimeMillis());
        n.number = 2;
        n.setLatestEventInfo(this, title, body, pi);
        n.defaults = Notification.DEFAULT_ALL;
        nm.notify(UNIQUE_ID, n);
    }
    

    after your activity launched, you must cancel that notification using the id(UNIQUE_ID)

                  try {
            nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
            nm.cancel(UNIQUE_ID);
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In the following code upto what scope the anonymous array referred by $ref is
I am following this tutorial http://www.codeproject.com/KB/cpp/authforwebservices.aspx They have this in the tutorial [SoapHeader(Authentication, Required
I want to use the webcam as camera in android emulator . I referred
On MSDN, one can read following: Reference types are also referred to as objects
The C# 3.0 spec has the following code example in section 10.6.1.3 Output parameters:
i have a data service hosted in azure from which i am sending notification
I have referred to the following question at: Using foreach loop to iterate through
I'm following this tutorial about building a multilingual web sites using PHP gettext http://onlamp.com/pub/a/php/2002/06/13/php.html
I am a beginner in both java and android. I am using asynchronous task
I would like to use CasperJS in node.js. I have referred to the following

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.