我想询问是否可以从另一个非活动类
启动一个非活动类即:
public class nubmerOne {
String data = "send me please";
public String getInfo(){
if (/*something happens*/){
//start Class numberTwo with some data
}
return "";
}
}
public class numberTwo { //this class is started when condition in class One is true
String dataPlus = "";
public String dosomething(){
//started from class numberOne and get data
dataPlus = data + "";
return dataPlus;
}
}
我知道在BroadcastReceiver,扩展Activity和Service的类之间可以实现这一点,芽可以在两个类中完成吗?
答案 0 :(得分:0)
我不确定我理解你的问题,但这看起来就像是经典的Java。
如果条件满足,您的第一个类必须创建第二个类的实例,并在第二个类的构造函数中传递数据。
public class nubmerOne {
String data = "send me please";
public String getInfo(){
if (/*something happens*/){
//start Class numberTwo with some data
NumberTwo numberTwo = new NumberTwo (data);
numberTwo.doSomething();
}
return "";
}
}
public class NumberTwo { //this class is started when condition in class One is true
private String data;
public NumberTwo (String data){
this.data = data;
}
String dataPlus = "";
public String dosomething(){
//started from class numberOne and get data
dataPlus = data + "";
return dataPlus;
}
}
希望我帮助过。