2

I start an activity using the following code for a given result:

startActivityForResult(
    new Intent(
        getActivity(),
        StudentDetails.class
    ).putExtra(
        GeneralFunctions.EXTRA_STUDENT_ID,
        (String) studentsListInUse.get(index)
                                  .valueForKey(GeneralFunctions.STUDENT_ID)
    ),
    GeneralFunctions.REQUEST_STUDENTS_EDITING
);

Then in some other point I finish it:

finishActivity(GeneralFunctions.REQUEST_STUDENTS_EDITING);

And start it again with another student´s data:

startActivityForResult(
    new Intent(
        this,
        StudentDetails.class
    ).putExtra(
        GeneralFunctions.EXTRA_STUDENT_ID,
        (String) attendance.valueForKey(GeneralFunctions.STUDENT_ID)
    ),
    GeneralFunctions.REQUEST_STUDENTS_EDITING
);

The problem is, when I go back the screens, every single activity displaying student´s details remain on the stack. In the documentation there's nothing besides:

The request code of the activity that you had given to startActivityForResult(). If there are multiple activities started with this request code, they will all be finished.

So what extra detail is missing here? It should simply finish all activities that were started with a given resultCode.

Blo
  • 11,903
  • 5
  • 45
  • 99
Stephen Lynx
  • 1,077
  • 2
  • 14
  • 29
  • 1
    I found a solution for what I needed. Using the flag FLAG_ACTIVITY_CLEAR_TOP. It worked even a little better than finishing an activity for a given result would. But I still dont know why finishActivity wont work. – Stephen Lynx Apr 19 '14 at 00:47
  • I'm glad you found a solution but I've been looking at this trying to figure out why. I've never used that method but I wonder if you only had one instance of that child activity if it would make a difference. Also, are you calling `setResult()` in the child Activity? – codeMagic Apr 19 '14 at 00:58
  • Child activity being the one that is suposed to be finished? I had just one instance of it before starting the second and calling finishActivity. Otherwise both would be terminated. And no, I didnt called setResult. Would that make a difference? FinishActivity cant finish an activity wich result hadnt been set? – Stephen Lynx Apr 19 '14 at 01:02
  • As I said, I've never used it so I don't know for sure. So, I was just thinking of things that *may* make a difference, though the docs didn't indicate such an issue. – codeMagic Apr 19 '14 at 01:05

0 Answers0