【发布时间】:2017-01-22 14:53:43
【问题描述】:
我是 android 和 java 的新手,我有这个意图
String temp = intent.getStringExtra("msg");
它连续返回多个单词 像 "msg a" , "msg b" , "msg c" ...我想将所有这些单词存储到另一个字符串中
这是我尝试过的
String anothertemp = temp;
但问题是它只存储最后一个单词“msg c”。 我的意思是它会用旧词替换和覆盖新词
我想将所有这些单词存储在一个新字符串中,并且每个单词都像这样在新行中存储
msg a
msg b
msg c
顺便说一句,我也已经尝试过这些
String temp = intent.getStringExtra("msg")+ "\n" ;
&
String anothertemp = temp+ "\n";
仍然有同样的问题。 对不起我的英语不好
编辑一个
这是我的意图
class NLServiceReceiver extends BroadcastReceiver{
@Override
public void onReceive(Context context, Intent intent) {
if(intent.getStringExtra("command").equals("list")){
int i=1;
for (StatusBarNotification sbn : NLService.this.getActiveNotifications()) {
Intent i2 = new Intent("notificationmsg");
i2.putExtra("msg",i +" " + sbn.getPackageName() + "\n");
sendBroadcast(i2);
i++;
}
}
}
}
这就是我的称呼
class NotificationReceiver extends BroadcastReceiver{
@Override
public void onReceive(Context context, Intent intent) {
String temp = intent.getStringExtra("msg") + "\n";
String anothertemp = temp;
}
}
编辑两个
假设我们有 3 个通知“msg1”、“msg2”和“msg3”,在 NotificationReceiver 类的 onReceive 方法中,当 msg1 字符串发布时,它会一个一个(一个接一个)发布字符串,然后它会发布 msg2细绳。它不会同时发布所有这些味精……这就是将要发生的事情;它将发布通知 msg 1 字符串,然后将发布 msg2 字符串,它将在 msg 1 上被替换和覆盖,然后它将发布 msg 3,它将在 msg2 上被替换和覆盖......所以最后我只有可以得到 msg 3 字符串...
感谢您的帮助
【问题讨论】:
-
你的意思是像
anothertemp += temp;吗? -
@Orin2005 不,我的意思是我希望所有意图的字符串味精都在一个字符串中
-
你能多说一下
intent的内容吗?您的消息是否总是由诸如“msg”之类的常量子字符串分隔? -
@markspace 我在我的编辑中添加了意图,请检查它..它是通知侦听器的一部分。你可以在这里找到它link
标签: java android string android-intent text