Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Intent problem, return value (Android)

Tags:

java

android

I have an application that opens another 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 creates Repository.class). Thank you for your help. Michaël

like image 890
Michaël Avatar asked May 25 '09 00:05

Michaël


People also ask

What is Intent setType in android?

setType(String mimeType) input param is represent the MIME type data that u want to get in return from firing intent(here myIntent instance). by using one of following MIME type you can force user to pick option which you desire. Please take a Note here, All MIME types in android are in lowercase.

What are the Intent actions in android?

An Intent object carries information that the Android system uses to determine which component to start (such as the exact component name or component category that should receive the intent), plus information that the recipient component uses in order to properly perform the action (such as the action to take and the ...

What is Intent Flag_activity_new_task in android?

FLAG_ACTIVITY_NEW_TASK is equivalent to launchMode=singleTask and in there I read. However, if an instance of the activity already exists in a separate task, the system routes the intent to the existing instance through a call to its onNewIntent() method, rather than creating a new instance.

What is android Intent Action view?

An intent allows you to start an activity in another app by describing a simple action you'd like to perform (such as "view a map" or "take a picture") in an Intent object.


1 Answers

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.

like image 55
buster Avatar answered Nov 03 '22 00:11

buster