推送通知中包含的数据是否可以在另一个视图的文本视图显示中显示?

时间:2013-09-24 12:02:38

标签: android

     @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中。我怎么能这样做?

2 个答案:

答案 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)

执行此操作的唯一方法是创建活动,该活动将在用户点击通知项目后打开。