getextras()。getstring(" test")和getstringextra(" test")之间有什么区别? [英] What is the difference between getextras().getstring("test") and getstringextra("test")?

查看:163
本文介绍了getextras()。getstring(" test")和getstringextra(" test")之间有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看不出它们之间有什么大的区别,但是第一个请求Bundle的帮助,而另一个直接从intent获取字符串。在我看来,这是一个标准程序,因为它始终是我从其他代码中看到的。



MainActivity:



I don't see any big difference between them but the first one asks the help of Bundle while the other one directly gets the string from the intent. It seems to me that this is a standard procedure as it is always what I see from the other code.

MainActivity:

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
    super.onActivityResult(requestCode, resultCode, data);

    TextView usersNameMessage = (TextView) findViewById(R.id.users_name_message);

    String nameSentBack = data.getStringExtra("UsersName");

    usersNameMessage.append(" " + nameSentBack);
}





SecondActivity:





SecondActivity:

protected void onCreate(Bundle savedInstanceState)
{
	super.onCreate(savedInstaceState);
	
	setContentView(R.layout.second_layout);
	
	// gets the intent that called the SecondScreen activity.
	Intent activityThatCalled = getIntent();
	// gets the data passed by the previous activity by providing the name.
	String previousActivity = activityThatCalled.getExtras().getString("nameOfThedataToBePassed");

}





我的尝试:



我试过搜索但未找到特定于此用法的答案。



What I have tried:

I tried searching about it but haven't found an answer specific to this usage.

推荐答案

getExtras [ ^ ]首先返回一个Bundle,而 getStringExtra [ ^ ]直接返回一个字符串。
getExtras[^] first returns a Bundle, while getStringExtra[^] directly returns a string.


这篇关于getextras()。getstring(" test")和getstringextra(" test")之间有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆