简体   繁体   English

在eclipse上将数据从一个屏幕传输到另一个屏幕

[英]Transfer data from one screen to another on android eclipse

Hi am newbie to java and android. 嗨,我是Java和android的新手。

Assume function demo() from the screenone is going to display some values on Textview which is on the same screen(screenone). 假设来自screenone的功能demo()将在同一屏幕(screenone)上的Textview上显示一些值。

But i need to display that resultant value to the next screen ie.(screen two) 但是我需要在下一个屏幕上显示该结果值。(屏幕二)

public void demo(){
{
 .....
 .....
}

So i have included these line to 所以我将这些行包括在内

screenoneActivity.java screenoneActivity.java

Intent nextScreen = new Intent(getApplicationContext(), SecondtwoActivity.class);
nextScreen.putExtra("","");
startActivity(nextScreen);
demo();

ScreentwoActivity.java ScreentwoActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) 
{

    super.onCreate(savedInstanceState);

    setContentView(R.layout.main1);

    TextView txtName = (TextView) findViewById(R.id.textView1);

    Intent i = getIntent();

    txtName.setText(name);

I did these things so far.I don't know how to do transfer data from demo() function to the next screen. 到目前为止,我已经做了这些事情,我不知道如何将数据从demo()函数传输到下一个屏幕。

Can anyone give me clues or ideas to achieve this. 任何人都可以给我线索或想法来实现这一目标。

Thanks a lot!.. 非常感谢!..

You need to send some value into the putExtra methods parameters to be able to get something out of it. 您需要将一些值发送到putExtra方法参数中,以便能够从中获取某些价值。

In your first activity(A): 在您的第一个活动(A)中:

Intent i = new Intent(A.this, B.class);
i.putExtra("someName", variableThatYouNeedToPass);
startActivity(i);

In your second activity(B): 在您的第二项活动(B)中:

Bundle extras = getIntent().getExtras();
int fetchedVariable = extras.getInt("someName");

Write the below code in demo() function: 在demo()函数中编写以下代码:

Intent nextScreen = new Intent(getApplicationContext(), SecondtwoActivity.class);
       nextScreen.putExtra("","");
       startActivity(nextScreen); 

In nextScreen.putExtra("",""); nextScreen.putExtra("",""); provide some key and value like: 提供一些关键和价值,例如:

nextScreen.putExtra("name","ABC");

Now in SecondActivity, write: 现在在SecondActivity中,编写:

@Override
protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

    setContentView(R.layout.main1);

    TextView txtName = (TextView) findViewById(R.id.textView1);

    Intent i = getIntent();
    Bundle bundle = i.getExtras();

    txtName.setText(bundle.getString("name"));

In ScreenoneActivity 在ScreenoneActivity中

Intent act2=new Intent(this,Activity2.class);
    act2.putExtra("A",a);
    startActivity(act2);

In ScreentwoActivity class 在ScreentwoActivity类中

Intent i = getIntent();
Bundle extras = getIntent().getExtras(); 
int a = extras.getInt("A");
txtName.setText(a);

in onCreate : 在onCreate中:

Bundle extras = getIntent().getExtras(); 
String value;

if (extras != null) 
{
    value= extras.getString("key");
}

https://stackoverflow.com/questions/10752501/how-can-we-go-to-next-page-in-android/10752516#10752516 https://stackoverflow.com/questions/10752501/how-can-we-go-to-next-page-in-android/10752516#10752516

google it is very basic ..... 谷歌这是非常基本的.....

android using intent.... android使用意图...

Vogella Ariticle Vogella Ariticle

in activity 1- 在活动1中

Intent i = new Intent(this, ActivityTwo.class);
i.putExtra("Value1", "This value one for ActivityTwo ");
i.putExtra("Value2", "This value two ActivityTwo");

startActivity(i);

In activity 2 - in onCreate finction 在活动2中-在onCreate函数中

Bundle extras = getIntent().getExtras();

if (extras == null) {
        return;
        }
// Get data via the key
String value1 = extras.getString(Intent.EXTRA_TEXT);
if (value1 != null) {
    // Do something with the data
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在Android中将数据从一个屏幕传输到另一个屏幕? - How to transfer data from one Screen to another in android? 是否可以在没有“ Touch to Beam”屏幕的情况下将NFC数据从一个Android设备传输到另一设备? - Is it possible to transfer NFC data from one Android device to another without the 'Touch to Beam' screen? 在Android上将数据从一个应用程序传输到另一个应用程序 - Transfer data from one app to another app on Android 将数据库数据从一个Android设备传输到另一个 - Transfer database data from one android device to another 如何在Android(SQlite)中将本地存储数据从一台设备传输到另一台设备 - How to transfer the localstorage data from one device to another in android(SQlite) 如何在Android中将数据从一个应用程序传输到另一个应用程序 - How to transfer data from one app to another app in android 如何在Android中将数据从一项活动转移到另一项活动? - How do I transfer data from one activity to another in Android? 如何在android中将数据从一个活动传输到另一个活动 - How to transfer data from one activity to another in android 如何将数据从一个应用程序传输到android中的另一个应用程序 - How transfer data from one app to another app in android 是否可以在没有“触摸到光束”屏幕的情况下将NFC文件从一台Android设备传输到另一台? - Is it possible to transfer NFC files from one Android device to another without the 'Touch to Beam' screen?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM