馬上加入Android 台灣中文網,立即免費下載應用遊戲。
您需要 登錄 才可以下載或查看,沒有帳號?註冊
x
本帖最後由 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);//發起通知
- }
- });
- }
- }
複製代碼 |