开发者

problem in moving data's from one page to the other in android

开发者 https://www.devze.com 2023-02-19 21:42 出处:网络
hi in my app i have three Activities named as A,B and C. i am getting some data such as names in Activity A and Date of Birth in Activity B. Now in Activity C i want display those names and date of bi

hi in my app i have three Activities named as A,B and C. i am getting some data such as names in Activity A and Date of Birth in Activity B. Now in Activity C i want display those names and date of birth. I tried using the steps in the following link

how to move data's from one page to the other in Android

i am able to move data from Activity B to C, but the data stored in Activity A are not been visible

Following is the code which i have placed in Activity A

Intent myIntent = new Intent(getBaseContext(), UserInformation.class);
              myIntent.putExtra("i1", name);
              myIntent.putExtra("i2", addlress);
startActivityForResult(myIntent, 0);

Following is the code which i have used in Activity B

Intent myIntent = new Intent(getBaseContex开发者_JAVA百科t(), UserManual.class);
        myIntent.putExtra("i3", regno);
        myIntent.putExtra("i4", dob);
startActivityForResult(myIntent, 0);

Following is the code which i have use in Activity C

@Override
public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);`

    Bundle extras = getIntent().getExtras();
    String i1 = extras.getString( "i1" );
    String i2 = extras.getString( "i2" );
    String i3 = extras.getString( "i3" );
    String i4 = extras.getString( "i4" ); 
    if((i1 != null) && (i2 != null))
    {
        s = i1 + i2;
        extras.putCharSequence("S", s);
    }
    if((i3 != null) && (i4 != null))
    {
        b = i3 + i4;
        extras.putCharSequence("B", b);
    }
}

I have place seperate text view's for both.

Pls explain me what is my error...


Well let's imagine the case being looked like this: A->B->C. Now the code: Activity B:

Bundles extras = getIntent().getExtras();
 String i1 = extras.getString( "i1" );
        String i2 = extras.getString( "i2" );
    Intent myIntent = new Intent(getBaseContext(), UserManual.class); 
myIntent.putExtra("i1", i1); 
myIntent.putExtra("i2", i2); 
myIntent.putExtra("i3", regno); 
myIntent.putExtra("i4", dob);
 startActivityForResult(myIntent, 0);

So activity A passed values to activity B and then activity B will passed all of values to activity C :)


Step #1: Get rid of getBaseContext(). Just use this.

Step #2: C does not magically get the extra's on the Intent used to start B, any more than a Web page C would magically get the GET parameters attached to a URL used to launch page B. B must put all extras onto the Intent it uses with startActivity() for C to be able to read them.

0

精彩评论

暂无评论...
验证码 换一张
取 消