如何将文本从通知传递到另一个活动? [英] How to pass text from notification to another activity?
问题描述
在我的应用程序中,当我单击列表视图项时,将显示一个通知,现在,当我单击该通知时,打开另一个活动并在另一个活动中显示通知内容.在这里,当我选择列表视图时,项目通知将随所选项目文本一起提供.在我选择了另一个列表视图项目之后,通知也附带了相关文本,但是确切的问题是当我打开该通知时,另一个活动中只会显示一个文本.请进行修正.
in my application, when i click list view item one notification will display, Now when i click that notification open another activity and display the notification content in another activity. Here when i select list view item notification will come with selected item text. After i select another list view item then also notification come with related text, but exact problem is when i open that notification, only one text will display in another activity.please fix it.
rmdListView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
showNotification();
}
现在通知方法为
public void showNotification() {
Uri soundUri = RingtoneManager
.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
// intent triggered, you can add other intent for other actions
Intent intent = new Intent(updateActivity.this,
NotificationReceiver.class);
intent.putExtra("Name", noti);
PendingIntent pIntent = PendingIntent.getActivity(updateActivity.this,
0, intent, 0);
Notification mNotification = new Notification.Builder(this)
.setContentTitle("Reminder!").setContentText(timeList + ":" + noti)
.setSmallIcon(R.drawable.logosmall).setContentIntent(pIntent)
.setSound(soundUri)
.build();
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
mNotification.flags |= Notification.FLAG_AUTO_CANCEL;
notificationManager.notify(0, mNotification);
}
推荐答案
最后我找到了该任务的答案.
onNewIntent(getIntent());
Oncreate()方法.
将此代码添加到您的活动中之后.
Finally i found answer for this task.First write this line into
onNewIntent(getIntent());
Oncreate() method.
After add this code to your Activity.
protected void onNewIntent(Intent intent) {
// TODO Auto-generated method stub
Bundle extras = getIntent().getExtras();
if(extras != null){
if(extras.containsKey("Name")){
setContentView(R.layout.notification);
// extract the extra-data in the Notification
ok_btn=(Button)findViewById(R.id.not_ok);
String msg = extras.getString("Name");
not_data = (TextView) findViewById(R.id.noti_txt);
not_data.setText(msg);
}
}
super.onNewIntent(intent);
}
对此任务的任何疑问都会提出您的问题.
any doubts in this task plse post ur question.
这篇关于如何将文本从通知传递到另一个活动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!