将数据从通知传输到新活动

时间:2013-04-24 14:41:10

标签: android

我有一个Activity用一些文字调用显示通知,点击通知后我想用该文本打开一个新的活动,所以我创建了通知:

NotificationManager notManager;
Notification myNot;
PendingIntent pIntent;
Intent intent;


    protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    Button startBtn = (Button)findViewById(R.id.btnStart);
    tvForNot = (TextView)findViewById(R.id.editText1);
    intent = new Intent(this, BrowserActivity.class);
    intent.putExtra("text", "textToSend");
    pIntent = PendingIntent.getActivity(this, 0, intent, 0);


    OnClickListener startBtnListener = new OnClickListener() {

        @Override
        public void onClick(View v) {
            textToSend = tvForNot.getText().toString();
            notManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
            myNot = new Notification(R.drawable.ic_launcher, "title", System.currentTimeMillis());

              func1(textToSend);
            notManager.notify(1,myNot );

        }
    };
    startBtn.setOnClickListener(startBtnListener);


}
public void func1 (String text){
    myNot.setLatestEventInfo(this, "title11", text, pIntent);
}

BrowserActivity我想要显示文字,但似乎我对传输的数据有一些问题

public class BrowserActivity extends Activity {

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.browser);

    Intent intent = getIntent();

    String fileName = intent.getStringExtra("text");

    TextView textViewDisplay = (TextView) findViewById(R.id.textW);
    textViewDisplay.setText(fileName);

  }
}

fileName始终为null!我的问题在哪里?为什么我无法提取这些数据?

0 个答案:

没有答案