2011-05-18 16 views
0

我想使用通知发送2个字符串,但我不知道该怎么做。我为我的字符串使用putExtra,但在其他活动中,我得到空。我不知道如何处理其他活动。我在网上阅读了这篇文章,但我没有注意。谁能帮我?如何使用通知发送2个字符串?

这里是我的代码:

private void setNotifiy(){ 
    notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); 
    CharSequence NotificationTicket = "You have a notification"; 

    //CharSequence NotificationContent = ; 
    CharSequence contentTitle = "You are close to "+name_shop+"!!!"; 
    CharSequence contentText ="So,you can go for shopping:)"; 

    long when = System.currentTimeMillis(); 

    Notification notification = new Notification(R.drawable.icon, 
      NotificationTicket, when); 

    Context context = getApplicationContext(); 

    Intent notificationIntent = new Intent(this, ShopsOnMap.class); 
    notificationIntent.putExtra("latshop",lat_choose); 

    notificationIntent.putExtra("longshop", long_choose); 

    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, 
      notificationIntent, 0); 


    notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent); 

    notificationManager.notify(NOTIFICATION_ID, notification); 
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP 
      | Intent.FLAG_ACTIVITY_SINGLE_TOP); 

} 

在课堂上ShopsOnMap我写的只是这样的:

String q = getIntent().getStringExtra("latshop"); 
System.out.println("!!"+q+"$$"); 

,我获得Q = NULL。

我需要一个简单的例子,或任何想法可以帮助我。谢谢。

+0

您是否确认'lat_choose'不为空? – Haphazard 2011-05-18 17:03:37

+0

我把System.out.println(lat_choose),它不是null。 – Gaby 2011-05-18 17:29:14

回答

0

getActivity()通话使用FLAG_UPDATE_CURRENT,而不是0,为第四个参数,因此新Intent额外应用于PendingIntent

+0

感谢您的回答。我设法解决了这个问题。 – Gaby 2011-05-18 18:02:31

相关问题