綁定帳號登入

Android 台灣中文網

打印 上一主題 下一主題

[求助] 訊息欄通知(Notification)

[複製連結] 查看: 1096|回覆: 1|好評: 0
跳轉到指定樓層
樓主
wind8894 | 收聽TA | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
發表於 2012-5-28 11:41

馬上加入Android 台灣中文網,立即免費下載應用遊戲。

您需要 登錄 才可以下載或查看,沒有帳號?註冊

x
本帖最後由 wind8894 於 2012-5-28 11:47 編輯

參考這篇文章後,可以正常跳出通知,按下去也可以正常換頁
http://apk.tw/forum.php?mod=view ... &fromuid=160066

但是要怎麼把ActNotifyDemo這頁給關閉呢?

要怎麼像這樣能夠開啟另一個頁面後把目前這個頁面給關閉,按下返回時才不會重複顯示上一個頁面
  1. Intent intent= new Intent(ActNotifyDemo.this,condition_control.class);                   
  2. startActivity(intent);
  3. finish();
複製代碼
代碼如下,我有兩個activity,一個是ActNotifyDemo,另一個是condition_control
  1. public class ActNotifyDemo extends Activity {
  2.     Button _btn1;
  3.    
  4.     /** Called when the activity is first created. */
  5.     @Override
  6.     public void onCreate(Bundle savedInstanceState) {
  7.         super.onCreate(savedInstanceState);
  8.         setContentView(R.layout.main);


  9.         _btn1 = (Button)findViewById(R.id.button1);
  10.         _btn1.setOnClickListener(new OnClickListener(){
  11.             //觸發通知
  12.             public void onClick(View arg0) {
  13.                 //獲得通知管理器
  14.                  NotificationManager manager = (NotificationManager) getSystemService(
  15.                          Context.NOTIFICATION_SERVICE);
  16.                  //構建一個通知對像
  17.                  Notification notification = new Notification(R.drawable.icon,
  18.                             "通知", System.currentTimeMillis());

  19.                  PendingIntent pendingIntent = PendingIntent.getActivity(
  20.                          ActNotifyDemo.this,0,new Intent(ActNotifyDemo.this,condition_control.class),0);
  21.                  
  22.                  notification.setLatestEventInfo(getApplicationContext(),
  23.                          "通知標題",
  24.                          "通知顯示的內容",
  25.                          pendingIntent);
  26.                  notification.flags|=Notification.FLAG_AUTO_CANCEL; //自動終止
  27.                  notification.defaults |= Notification.DEFAULT_SOUND; //默認聲音
  28.                  manager.notify(0, notification);//發起通知
  29.             }
  30.         });
  31.     }
  32. }
複製代碼
「用Android 就來APK.TW」,快來加入粉絲吧!
Android 台灣中文網(APK.TW)
收藏收藏1 分享分享 分享專題
用Android 就來Android 台灣中文網(https://apk.tw)
回覆

使用道具 舉報

沙發
 樓主| wind8894 | 收聽TA | 只看該作者
發表於 2012-6-1 00:38
自行解決了

點下notification啟動的Activity,裡面的按鈕按下去後啟動ActivityNotifyDemo的Intent多加上
  1. intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
複製代碼

評分

參與人數 1幫助 +1 收起 理由
ploglin + 1

查看全部評分

用Android 就來Android 台灣中文網(https://apk.tw)
回覆 支持 反對

使用道具 舉報

您需要登錄後才可以回帖 登錄 | 註冊

本版積分規則