Use an intent to send data to my activity

2019-01-19 11:52发布

I have a server running that notifies the user with a statusbar notification that opens my main activity, how can I pass data to my activity trough that intent?

2条回答
smile是对你的礼貌
2楼-- · 2019-01-19 12:06

MainActivity

Intent intent = new Intent(MainActivity.this,SecondActivity.class);
intent.putExtra("extra_text", string); 
startActivity(intent);

SecondActivity

 String text = getIntent().getStringExtra("extra_text");
查看更多
\"骚年 ilove
3楼-- · 2019-01-19 12:12

Use Intent.putExtra(..):

intent.putExtra("keyName", "somevalue");

This method is overloaded and takes various types as second argument: int, byte, String, various arrays..

To get the data out use appropriate getXYZExtra(). For String this is:

getStringExtra(String keyName)
查看更多
登录 后发表回答