我有一个通知,在通过上述通知打开活动时,应该给我一些参数。
private void notify_newOrders(int count) {
int icon = R.drawable.ic_notification;
String ns = Context.NOTIFICATION_SERVICE;
NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);
CharSequence tickerText = infotext;
long when = System.currentTimeMillis();
Notification notification = new Notification(icon, tickerText, when);
Context context = getApplicationContext();
CharSequence contentTitle = "Title";
CharSequence contentText = "Infotext";
Intent notificationIntent = new Intent(this, TestActivity.class);
notificationIntent.putExtra("resuming", "123");
notificationIntent.setAction("resuming");
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
notification.flags |= Notification.DEFAULT_ALL;
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notification.number = count;
notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
mNotificationManager.notify(WORKNOTIFICATION_ID, notification);
}
在我的活动中,我有以下内容:
@Override
public void onCreate(Bundle savedInstanceState)
{
try{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Bundle extras = getIntent().getExtras();
if(extras != null)
{
Log.d("YAY","got extras");
}
问题是,我从来没有得到任何额外的东西。我在这里经历过类似的(已解决的)问题,并试图找出他们工作的原因,而我的工作并没有证明是无用的。救命啊!
在logCat中我得到了这些,不知道它们是否相关:
INFO/ActivityManager(59): Starting activity: Intent { act=resuming flg=0x24000000 cmp=com.test.test/.TestActivity bnds=[0,101][320,165] (has extras) }
WARN/ActivityManager(59): startActivity called from non-Activity context; forcing Intent.FLAG_ACTIVITY_NEW_TASK for: Intent { act=resuming flg=0x24000000 cmp=com.test.test/.TestActivity bnds=[0,101][320,165] (has extras) }
答案 0 :(得分:2)
原来是正确的做法
@Override
public void onNewIntent(Intent intent)
答案 1 :(得分:0)
看起来您的活动未创建,而是恢复了。将你的getExtras代码从onCreate()移到onResume(),这应该可行。