Reputation: 1127
I have my main activity which calls a second activity via startActivityForResults
. My second activity then calls a third activity via startActivityForResults
, but in this process my second activity finishes
. Now the third activity will finish
, but will need to send back a result code via setResult
. My first activity has the onActivityResult
method in place, but never receives anything or is never called.
I'm having trouble managing this issue between the three activities. What is the simplest way to take care of this?
Upvotes: 0
Views: 85
Reputation: 1494
The simplest may be the use of a Singleton class.
public class ResultHolder {
private String result; // Whichever result code you need to persist
public String getResult() {return result;}
public void setResult(String result) {this.result = result;}
private static final ResultHolder holder = new ResultHolder();
public static ResultHolder getInstance() {return holder;}
}
In your activity that posts the result code:
ResultHolder.getInstance.setResult(whateverResultCode);
In your activity that receives the result code:
String resultCode = ResultHolder.getInstance.getResult();
Hope this helps.
Upvotes: 1