有两种方法可以解决您的问题
选项1 :
public class MainClass extends Activity {
private String myString = "";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// .... your code
Timer smsThread = new Timer();
GetSMSThread getSMSThread = new GetSMSThread();
smsThread.scheduleAtFixedRate(getSMSThread, 0, 100000);
myString = "assigning some value";
}
public class GetSMSThread extends TimerTask {
@Override
public void run() {
myString = "manipulating Values";
}
}
}
选项 2:
public class MainClass extends Activity {
private String myString = "";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// .... your code
myString = "assigning some value";
Timer smsThread = new Timer();
GetSMSThread getSMSThread = new GetSMSThread(myString);
smsThread.scheduleAtFixedRate(getSMSThread, 0, 100000);
}
}
获取短信线程:
public class GetSMSThread extends TimerTask {
private String myString = "";
public GetSMSThread(String mString) {
myString = mString;
}
@Override
public void run() {
myString = "manipulating Values";
}
}