我希望当计时器触发时,即使活动已暂停,也能将活动置于前台。
非常感谢。
以下是我的代码:
非常感谢。
以下是我的代码:
package cem.examples.wsAct;
import something....
public class main extends Activity {
TextView tvResult, tvCount;
Button btn;
Timer timer;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// setviews ....
// (find on the layout and bind them to the fields)
timer = new Timer();
timer.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
runOnUiThread(new Runnable() {
@Override
public void run() {
// bring activity to front
f_UpdateUI();
}
});
}
}, 1000, 3000);
}
void f_UpdateUI() {
String result = f_RetrieveFromWebService();
// ??? Code... ???
// If the activity is sended to back (how can I get it's state?)
// Bring the activity even if it is paused or stopped (here is the lost part)
}
private String f_RetrieveFromWebService() {
// connect to web service and return string
return "ta ta taaaaa";
}
}