首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > 移动开发 >

notification中发起activity有关问题

2012-09-02 
notification中发起activity问题String ns Context.NOTIFICATION_SERVICE?? ? NotificationManager mNo

notification中发起activity问题

String ns = Context.NOTIFICATION_SERVICE;?
? ? NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);?
? ? int icon = R.drawable.icon; ? ? ?
? ? long when = System.currentTimeMillis();?
? ? Notification notification = new Notification(icon, "Test Notification", when);?
?
?
? ? Context context = getApplicationContext(); ? ? ??
?
? ? Bundle bundle = new Bundle();?
? ? bundle.putString("action", "view");?
? ? Intent notificationIntent = new Intent(this, MainActivity.class);?
? ? notificationIntent.putExtras(bundle);?
?
? ? PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, Intent.FLAG_ACTIVITY_NEW_TASK);?
? ? notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent); ? ? ?
? ? mNotificationManager.notify(1, notification);?

?

下面是要取出"action", 的值

Bundle bundle = this.getIntent().getExtras();?
?
? ? if(bundle != null)?
? ? {?String action = bundle.getString("action");?
? ? ? ? ? ? performAction(action)?
? ? }?
程序呢按照预期执行,只是当我返回程序,把状态栏缩小,然后回到屏幕通过程序的图标发起程序竟然从上次notivication点击的时候发起,

? ? ? ?

可以通过

Intent intent = getIntent();?
int flags = intent.getFlags();?
boolean launchedFromHistory = ((flags & Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY)

来判断一下是不是从历史中发起的

热点排行