1

I created a library, and its library has 4 activity. I move between theese activitys with intent, but i dont know how could i send result data, to the main application? I start my library like this:

Intent intent = new Intent(this, LibraryFirstActivity.class);
startActivityForResult(intent, 1);

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == 1){
        if (resultCode == RESULT_OK){
            String result = data.getStringExtra("result");
            Log.d("result", result);
        }
        if (resultCode == RESULT_CANCELED){
            Toast.makeText(this, "CANCELED", Toast.LENGTH_SHORT).show();
        }
    }
}

I start LibraryFirstActvity. In LibraryFirstActivity i go to the LibrarySecondActivity:

Intent intent = new Intent(this, LibrarySecondActivity.class);
startActivity(intent);
finish();

But i can go to the LibraryThirdActivity too, or other. So how can i return to the main app onActivityResult() method?

lopez.mikhael
  • 9,943
  • 19
  • 67
  • 110
just
  • 1,900
  • 4
  • 25
  • 46

2 Answers2

0

In librarySecondActivity you should also start activityForResult and get the value with onActivityResult. You then send back info from third to second and from second to first (main). With the same logic you can add fourth. Think recursively!

Kelo
  • 453
  • 1
  • 3
  • 17
0

Check this link for more details about startActivityForResult()

You have to @Override onActivityResult() like this:

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == CONST_REQUEST_CODE) {
        // your code
    }        
}

Call startActivityForResult() as:

startActivityForResult(intentName, CONST_REQUEST_CODE);
Paritosh
  • 2,097
  • 3
  • 30
  • 42