我在少数地方开始使用startActivityForResult()
的活动,而在其他几个地方使用startActivity()
开展活动。我的新活动使用setResult()
方法设置结果。我是否会收到任何错误,这是一个很好的做法吗?
答案 0 :(得分:0)
你可以这样做。那没问题。如果您在调用活动中不需要结果,那么您不需要使用startActivityForResult()
启动活动。这类似于Java中的以下内容:
// A method that does something on Monday, and returns a boolean result indicating
// whether it did something or not
boolean doSomethingOnMonday() {
if (monday) {
// Do something here and tell the caller that we did it
...
return true;
}
// Don't do anything. Tell the caller that we didn't do anything
return false;
}
你可以像这样使用它:
boolean monday = doSomethingOnMonday();
或者像这样:
if (doSomethingOnMonday()) {
...
}
或者像这样:
// Do something on Monday, but I don't care if we did it or not, so ignore the
// method's return value
doSomethingOnMonday();