@Override
public void onStart(Intent intent, int startId) {
// TODO Auto-generated method stub
super.onStart(intent, startId);
Toast.makeText(this, "Service started", Toast.LENGTH_SHORT).show();
final String str=intent.getStringExtra("str");
Log.v("debugging", str);
NotificationManager nm = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
Intent i = new Intent(Myservice.this, Display.class);
PendingIntent pi = PendingIntent.getActivity(Myservice.this, 0, i, 0);
Notification n = new Notification(R.drawable.ic_launcher,str, System.currentTimeMillis());
n.setLatestEventInfo(Myservice.this,"New message for you: ", str, pi);
nm.notify(1,n);
}
现在我想将“str”即数据显示到另一个xml的textview中。我怎么能这样做?
答案 0 :(得分:1)
做这样的事情:
Intent i = new Intent(Myservice.this, Display.class);
i.putExtras("str_key", str);
在Display Activity
中获取str
就像这样:
String strValue = getIntent.getExtras().getString("str_key");
答案 1 :(得分:0)
执行此操作的唯一方法是创建活动,该活动将在用户点击通知项目后打开。