android在屏幕之间导航值
在我的应用程序中,我希望单击按钮(在第一个屏幕中)调用web服务。在第一个屏幕中,我将输入一个输入。 基于该输入值,web服务必须运行。单击按钮后,我调用了一个新的意图,并在那里调用了web服务,但如何将该值从一个屏幕传递到另一个屏幕 我的代码: 这是按钮点击(第一屏) 这是web服务(单击按钮后)android在屏幕之间导航值,android,Android,在我的应用程序中,我希望单击按钮(在第一个屏幕中)调用web服务。在第一个屏幕中,我将输入一个输入。 基于该输入值,web服务必须运行。单击按钮后,我调用了一个新的意图,并在那里调用了web服务,但如何将该值从一个屏幕传递到另一个屏幕 我的代码: 这是按钮点击(第一屏) 这是web服务(单击按钮后) 您需要在调用intent中使用putExtra,并在另一个屏幕中获得该意图 例如,你可以这样打电话 Intent myIntent = new Intent(this, PlayVideoActi
您需要在调用intent中使用
putExtra
,并在另一个屏幕中获得该意图
例如,你可以这样打电话
Intent myIntent = new Intent(this, PlayVideoActivity.class);
myIntent.putExtra("KeyName", value);
startActivity(myIntent);
String value=getIntent().getStringExtra("Keyname");
现在,当另一个活动出现时,得到这样的值
Intent myIntent = new Intent(this, PlayVideoActivity.class);
myIntent.putExtra("KeyName", value);
startActivity(myIntent);
String value=getIntent().getStringExtra("Keyname");
这是一个使用示例,您可以使用putExtra for intent支持的类型。有两种方法。您可以使用额外或共享首选项。
共享数据参考:
编辑共享首选项中的数据
SharedReferences preferences=PreferenceManager.GetDefaultSharedReferences(此)
SharedReferences.Editor=首选项.edit()
putString(“名称”、“测试”)
commit() 从共享首选项检索数据
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
String name = preferences.getString("Name","");
if(!name.equalsIgnoreCase(""))
{
name = name+" Sethi"; /* Edit the value here*/
}
或
**putExtra:**
**pass data using putExtra at the time of calling intent.**
Intent myIntent = new Intent(this, PlayVideoActivity.class);
myIntent.putExtra("KeyName", value);
startActivity(myIntent);
**Retrive data from other activity**
String value=getIntent().getStringExtra("Keyname");