Android 台灣中文網
標題:
訊息欄通知(Notification)
[打印本頁]
作者:
wind8894
時間:
2012-5-28 11:41
標題:
訊息欄通知(Notification)
本帖最後由 wind8894 於 2012-5-28 11:47 編輯
參考這篇文章後,可以正常跳出通知,按下去也可以正常換頁
http://apk.tw/forum.php?mod=view ... &fromuid=160066
但是要怎麼把ActNotifyDemo這頁給關閉呢?
要怎麼像這樣能夠開啟另一個頁面後把目前這個頁面給關閉,按下返回時才不會重複顯示上一個頁面
Intent intent= new Intent(ActNotifyDemo.this,condition_control.class);
startActivity(intent);
finish();
複製代碼
代碼如下,我有兩個activity,一個是ActNotifyDemo,另一個是condition_control
public class ActNotifyDemo extends Activity {
Button _btn1;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
_btn1 = (Button)findViewById(R.id.button1);
_btn1.setOnClickListener(new OnClickListener(){
//觸發通知
public void onClick(View arg0) {
//獲得通知管理器
NotificationManager manager = (NotificationManager) getSystemService(
Context.NOTIFICATION_SERVICE);
//構建一個通知對像
Notification notification = new Notification(R.drawable.icon,
"通知", System.currentTimeMillis());
PendingIntent pendingIntent = PendingIntent.getActivity(
ActNotifyDemo.this,0,new Intent(ActNotifyDemo.this,condition_control.class),0);
notification.setLatestEventInfo(getApplicationContext(),
"通知標題",
"通知顯示的內容",
pendingIntent);
notification.flags|=Notification.FLAG_AUTO_CANCEL; //自動終止
notification.defaults |= Notification.DEFAULT_SOUND; //默認聲音
manager.notify(0, notification);//發起通知
}
});
}
}
複製代碼
作者:
wind8894
時間:
2012-6-1 00:38
自行解決了
點下notification啟動的Activity,裡面的按鈕按下去後啟動ActivityNotifyDemo的Intent多加上
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
複製代碼
歡迎光臨 Android 台灣中文網 (https://apk.tw/)
Powered by Discuz! X3.1