0
我正在android應用程序上工作。我需要從onpostexecute方法中獲取值。即我需要使用onpostexecute方法的返回值執行一些任務。我怎樣才能做到這一點?在這方面請幫助我。如何從android中的onpostexecute方法獲取返回值?
我的代碼:
boolean val= false;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
LongOperation1 op = new LongOperation1();
op.execute("");
//I want the value here again
}
private class LongOperation1 extends AsyncTask<String, Void, String> {
@Override
protected String doInBackground(String... params) {
loadFeed2();
return "Executed";
}
@Override
protected void onPostExecute(String result) {
dialog1.dismiss();
try {
dialog.dismiss();
//mystuff
val = true;
}
catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
@Override
protected void onPreExecute() {
dialog1 = ProgressDialog.show(Taketest.this, "Please wait...",
"Retrieving data ...", true);
}
@Override
protected void onProgressUpdate(Void... values) {
}
}
使用全局變量 – KOTIOS
調用內部postexecute(功能),傳遞價值該函數的參數 – Senthil
hmm是我使用全局變量....在onpostexecute方法我將值更改爲true。現在我想在oncreate方法中使用它。我怎樣才能得到這個價值? – Amrutha