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
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.
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 ...
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With