1

Anyone please help me how to do that.

I have a simple android application in that application i am receiving a notification throw service at the time of clicking the notification i am opening the new class in that class i want to display the notification text in textview

My doubt is how to pass notification text to activity

Thanks in advance

Krishna
  • 4,892
  • 18
  • 63
  • 98

2 Answers2

1

You would be starting the activity using startActivity(intent); Now before you do that, add intent.putExtraString(key,value). And inside activity, get the passed string using getIntent().getStringExtra(key)

NASSER
  • 5,900
  • 7
  • 38
  • 57
Aniket Awati
  • 1,381
  • 3
  • 13
  • 21
  • Thanks Aniket I done this but it forcefully closing the application – Krishna Jun 22 '11 at 18:49
  • 1
    This is not the way you debug it. You have to see the logcat output. There you would see in detail, whats going wrong and where. If you post that output with your issue, it may get solved. – Aniket Awati Jun 23 '11 at 05:16
0

To view message in activity and set to textView, for notification

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    onNewIntent(getIntent());
}

@Override
public void onNewIntent(Intent intent){
    Bundle extras = intent.getExtras();
    if(extras != null){
        if(extras.containsKey("NotificationMessage"))
        {
            setContentView(R.layout.notification_sample);
            String message = extras.getString("NotificationMessage");
            textView = (TextView) findViewById(R.id.textMessage);
            textView.setText(message);
        }
    }
}

refer to this link

Community
  • 1
  • 1
Amit Vaghela
  • 22,772
  • 22
  • 86
  • 142