关键代码:
private void Notific(ChatMsg msg) {
NotificationManager nm = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
Notification n = new Notification(android.R.drawable.stat_notify_chat,
msg.getText(), System.currentTimeMillis());
n.flags = Notification.FLAG_AUTO_CANCEL;
Intent i = new Intent(context, ChatActivity.class);
Bundle notiextras = new Bundle();
notiextras.putString("state", "initnoti");
notiextras.putString("myname", myname);
notiextras.putString("myid", myid);
notiextras.putString("otherid", msg.getOtherid());
notiextras.putString("myip", msg.getMyip());
notiextras.putString("otherip", msg.getOtherip());
notiextras.putString("date", msg.getDate());
notiextras.putString("name", msg.getName());
notiextras.putString("text", msg.getText());
i.putExtras(notiextras);
i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent contentIntent = PendingIntent.getActivity(context, 10, i, 0);
n.setLatestEventInfo(context, "你来消息了!", msg.getText(), contentIntent);
n.defaults = Notification.DEFAULT_VIBRATE | Notification.DEFAULT_ALL;
nm.notify(100, n);
Log.v("TextID", msg.getText());
}
if(intent!=null){
Log.v("extrasID", extras.toString()+""+myid);
Log.v("extrasID", extras.getString("state")+extras.getString("name"));
if(extras.getString("state").equals("initnoti")){
ChatMsg msg = new ChatMsg(myip,
otherip,
extras.getString("name"),
extras.getString("date"),
extras.getString("text"),
R.layout.example_list_say_he_item);
list.add(msg);
talkView.setAdapter(new ChatMsgViewAdapter(ChatActivity.this,list));
Log.v("ID", extras.getString("otherip")+" "+msg.getOtherip()+" "+msg.getMyip());
myip = msg.getMyip();
otherip = msg.getOtherip();
Log.v("ID", "initnoti"+" "+msg.getText()+" "+extras.getString("text"));
}
第一次跳转时notiextras.putString("text", msg.getText());设的只是多少,Log.v("ID", "initnoti"+" "+msg.getText()+" "+extras.getString("text"));打印的就是多少,但是第二次时,Log.v("ID", "initnoti"+" "+msg.getText()+" "+extras.getString("text"));打印的还是第一次的值,为嘛啊android
private void Notific(ChatMsg msg) {
NotificationManager nm = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
Notification n = new Notification(android.R.drawable.stat_notify_chat,
msg.getText(), System.currentTimeMillis());
n.flags = Notification.FLAG_AUTO_CANCEL;
Intent i = new Intent(context, ChatActivity.class);
Bundle notiextras = new Bundle();
notiextras.putString("state", "initnoti");
notiextras.putString("myname", myname);
notiextras.putString("myid", myid);
notiextras.putString("otherid", msg.getOtherid());
notiextras.putString("myip", msg.getMyip());
notiextras.putString("otherip", msg.getOtherip());
notiextras.putString("date", msg.getDate());
notiextras.putString("name", msg.getName());
notiextras.putString("text", msg.getText());
i.putExtras(notiextras);
i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent contentIntent = PendingIntent.getActivity(context, 10, i, 0);
n.setLatestEventInfo(context, "你来消息了!", msg.getText(), contentIntent);
n.defaults = Notification.DEFAULT_VIBRATE | Notification.DEFAULT_ALL;
nm.notify(100, n);
Log.v("TextID", msg.getText());
}
if(intent!=null){
Log.v("extrasID", extras.toString()+""+myid);
Log.v("extrasID", extras.getString("state")+extras.getString("name"));
if(extras.getString("state").equals("initnoti")){
ChatMsg msg = new ChatMsg(myip,
otherip,
extras.getString("name"),
extras.getString("date"),
extras.getString("text"),
R.layout.example_list_say_he_item);
list.add(msg);
talkView.setAdapter(new ChatMsgViewAdapter(ChatActivity.this,list));
Log.v("ID", extras.getString("otherip")+" "+msg.getOtherip()+" "+msg.getMyip());
myip = msg.getMyip();
otherip = msg.getOtherip();
Log.v("ID", "initnoti"+" "+msg.getText()+" "+extras.getString("text"));
}
第一次跳转时notiextras.putString("text", msg.getText());设的只是多少,Log.v("ID", "initnoti"+" "+msg.getText()+" "+extras.getString("text"));打印的就是多少,但是第二次时,Log.v("ID", "initnoti"+" "+msg.getText()+" "+extras.getString("text"));打印的还是第一次的值,为嘛啊android
解决方案 »
- android连接远程数据库定时出现登陆失败
- 关于Parcelable的createFromParcel及writeToParcel传递数组的问题
- 如何查看system.img的文件系统类型
- Android GPS小程序,真机上不工作....
- 输入一个字显示后有两个(在EditText框里组拼中文)
- 求助。广播监听问题
- 怎么让应用支持键盘控制?
- 播放视频时候怎么去除旁边的白边
- 【急】c#服务器用套接字与android服务端互通训,要双向的,我自己写了一个,不成功,求例子,求指导,急啊
- 在线急等:eclipse怎么导入gradle构建的android项目?
- 求助,android ADT模拟器如何修改默认IP?
- ANDROID读取VECTOR错误,
http://bbs.csdn.net/topics/390625246