对于Android studio,我的问题是我如何编写(Java Code)活动,其中avtivity 1调用活动2,活动1发送一个数字到活动2.之后,活动2打印出这个数字并增加它一,并将其发回活动1
提前感谢,如果这已经问过别人,那就很抱歉
答案 0 :(得分:1)
通过这些教程,您将能够进行2项活动相互沟通
开始另一项活动 http://developer.android.com/training/basics/firstapp/starting-activity.html
与其他片段进行通讯http://developer.android.com/training/basics/fragments/communicating.html
从活动中获取结果 http://developer.android.com/training/basics/intents/result.html
答案 1 :(得分:0)
您要执行的操作在官方文档中进行了说明:http://developer.android.com/training/basics/intents/result.html
答案 2 :(得分:0)
您可以使用" delegate"方法:
第一项活动:
public class Activity1 implements AsyncResponse {
...
public void printAndIncrement() {
Activity2 activity2 = new Activity2();
activity2.delegate = this;
activity2.doWhatIWant(3);
// destroy activity2
}
public void processFinish(int result) {
// do something with the result
}
}
第二项活动:
public class Activity2 {
public AsyncResponse delegate = null;
...
protected void doWhatIWant(int num1) {
Systel.out.println(num);
delegate.processFinish(num1+1);
}
}
(界面):
public interface AsyncResponse {
void processFinish(int result);
}