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?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
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)
回答2:
MainActivity
Intent intent = new Intent(MainActivity.this,SecondActivity.class);
intent.putExtra("extra_text", string);
startActivity(intent);
SecondActivity
String text = getIntent().getStringExtra("extra_text");