tags:

views:

1103

answers:

2

Hi, I have an application that open an other class using intent :

private void createRepository(){
        Intent j = new Intent(this, Repository.class);
        startActivityForResult(j, ACTIVITY_CREATE);
    }

In Repository.class we have the onActivityResult method :

public void onActivityResult(int reqCode, int resultCode, Intent data) {
      super.onActivityResult(reqCode, resultCode, data);

      switch (reqCode) {
        case (PICK_CONTACT) :
          if (resultCode == Activity.RESULT_OK) {
            Uri contactData = data.getData();
            c =  managedQuery(contactData, null, null, null, null);
            if (c.moveToFirst()) {
              //String name = c.getString(c.getColumnIndexOrThrow(People.NAME));
              num = c.getString(c.getColumnIndexOrThrow(People.NUMBER));

            }    

          }    
        break;
      }
      finish();
    }

I don't know how I can return the value of num to the first class (that create Repository.class). Thank you for your help. Michaël

+1  A: 

I think you got the directions mixed up.
In the Repository class you have to setResult() before calling finish. For additional Data you can putExtra() data. For example, set your result in the onCreate() function.

In your calling class (the one that starts Repository) you overwrite onActivityResult(int requestCode, int resultCode, Intent data) and get data with data.getBundleExtra().

Androids reference for Intent and Activity has good descriptions and the samples also contain a ReceiveResult and SendResult sample.

buster
Thank you for your answer. Finally I used this post to resolve my problem : http://stackoverflow.com/questions/768969/passing-a-bundle-on-startactivity
Michaël
A: 

Android is not Java just like J# is not java. They may appear to use the same syntax and possible libraries but they both are not Java.

mP
Java the programming language? Yes, it does use Java.
Isaac Waller
@Isaac Android is not Java. It may look like java but it cant be called java because bits are missing in terms of features and libraries.They *Google* carefully never claim that it is, for this very reason. If they did they would be sued and lose in the same way Microsoft got sued and lost when they created their own "flavour" of java. Sun have been very pragmatic in enforcing what is java and whats not. Its a good thing they have/are because it means Java has become a stable platform that remains consistent across OS platforms.
mP