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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:10:04+00:00 2026-05-27T16:10:04+00:00

Please take a look at my code: package com.yarin.android.Examples_04_23; import android.app.Activity; import android.app.Notification; import

  • 0

Please take a look at my code:

package com.yarin.android.Examples_04_23;

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

public class Activity01 extends Activity {
    Button m_Button1;

    //声明通知(消息)管理器
    NotificationManager m_NotificationManager;
    Intent m_Intent;
    PendingIntent m_PendingIntent;

    /**
     * Called when the activity is first created.
     */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        //初始化NotificationManager对象
        m_NotificationManager = (NotificationManager)  getSystemService(NOTIFICATION_SERVICE);

        //获取按钮对象
        m_Button1 = (Button) findViewById(R.id.Button01);


        //点击通知时转移内容
        m_Intent = new Intent(Activity01.this, Activity02.class);
        //主要是设置点击通知时显示内容的类
        m_PendingIntent = PendingIntent.getActivity(Activity01.this, 0, m_Intent, 0);


        m_Button1.setOnClickListener(new Button.OnClickListener() {
            public void onClick(View v) {
                Notification m_Notification = new Notification();
                //设置通知在状态栏显示的图标
                m_Notification.icon = R.drawable.img1;
                //当我们点击通知时显示的内容
                m_Notification.tickerText = "Button1通知内容...........";
                //通知时发出默认的声音
                m_Notification.defaults = Notification.DEFAULT_SOUND;
                //设置通知显示的参数
                m_Notification.setLatestEventInfo(Activity01.this, "Button1", "Button1通知", m_PendingIntent);
                //可以理解为执行这个通知
                m_NotificationManager.notify(0, m_Notification);
            }
        });


    }
}

When a user click on the button click , a notification will appear on the application bar. However, the notification will stay there for ever after a user have click on it
enter image description here

enter image description here

  • 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-27T16:10:05+00:00Added an answer on May 27, 2026 at 4:10 pm
     Notification notification = new Notification();
     notification.flags = Notification.DEFAULT_LIGHTS | Notification.FLAG_AUTO_CANCEL
    

    From the docs

    “Bit to be bitwise-ored into the flags field that should be set if the notification should be canceled when it is clicked by the user”

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

Sidebar

Related Questions

Please take a look at this XML code: <TableLayout android:id=@+id/tableLayout1 android:layout_width=fill_parent android:layout_height=fill_parent android:padding=10dip android:isScrollContainer=true
Please take a look at this code: template<class T> class A { class base
Please take a look at following code: #include <stdio.h> #include <iostream> using namespace std;
Please take a look at this piece of code. I'm allocating one byte for
Please take a look at this below line of code in JSF <h:inputText id=name
Please take a look at a segment of my Flex code: <mx:Accordion id=accordian width=100%
Please take a look at my code: #include <windows.h> #include <Sti.h> #include <iostream> #pragma
Please take a look at the following code: Public Sub Method(Of TEntity As EntityObject)(ByVal
Please take a look at this simple code: http://jsfiddle.net/kerp3/ The box has an inner
Please take a look at this piece of code I came up with. abstract

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.