tags:

views:

66

answers:

2

iam using intent to call activity here and i need to send to long variable to the other acitivity ?
Porjct.java

      Intent i = new Intent(ProjectList.this,RoleList.class);
  Bundle c = new Bundle();            
  c.putLong("PID", projectID );
  c.putLong("CTSID", castingTimeSlotID);
  i.putExtras(c);
  startActivityForResult(i,0);
  finish();

RoleList.java

public void onActivityResult(int requestCode, int resultCode, Intent data) {    
            Bundle c = new Bundle();
        c = data.getExtras();
    projectID = b.getLong("PID");
    castingTimeSlotID = b.getLong("CTSID");}

this is not working , Please help me out?

A: 

Edit:

The onActivityResult() should be in ProjectList.java - it will be called when your child Activity returns.

Your child Activity in RoleList.java should retrieve the data sent by the parent from the Bundle passed via onCreate()

If this is a little confusing; I suggest you read this first: http://www.remwebdevelopment.com/dev/a33/Passing-Bundles-Around-Activities.html - the example in there is very complete and they explain it better than I do. Notice how they pass data with key "mykey" from the parent Activity to the child; this is what you want to do.


Previous useless answer of mine follows

I think you don't need to retrieve the extras via a Bundle. Try this:

public void onActivityResult(int requestCode, int resultCode, Intent data) {    
    projectID = data.getLongExtra("PID");
    castingTimeSlotID = data.getLongExtra("CTSID");
}
Joubarc
that doesn't work , it returns null value;
Srikanth Naidu
I must admit I'm a bit confused - which code is in which Activity? If this is in the calling/parent Activity, what's in the child one? because you'll certainly need to return an Intent from it with setResult(int resultCode, Intent data). Could you post the code in your RoleList class too?
Joubarc
//ProjectList.java projectID and castingTimeSlotID are long variables having some value Intent i = new Intent(ProjectList.this,RoleList.class); Bundle c = new Bundle(); c.putLong("PID", projectID ); c.putLong("CTSID", castingTimeSlotID); i.putExtras(c); startActivityForResult(i,0);//RoleList.java public void onActivityResult(int requestCode, int resultCode, Intent data) { Bundle c = new Bundle(); c = data.getExtras(); projectID = c.getLong("PID",projectID); castingTimeSlotID = c.getLong("CTSID"); }this returns null
Srikanth Naidu
A: 

hey buddy i got the answer today

1 st activity on click

     Intent myIntent = new Intent(ProjectList.this,RoleList.class);
     myIntent.putExtra("key", variable);
     myIntent.putExtra("key", variable);
     startActivity(myIntent);
     finish();

2 nd activity on Create

    Intent myIntent = getIntent(); // this is just for example purpose
    myIntent.getExtras();
    PID = myIntent.getLongExtra("key", variable);
    CID = myIntent.getLongExtra("key", variable);

thats it working fine

Srikanth Naidu