i have a function in an activity where i check something. I call a webservice in that function (in doInbackground method ) and depending on the result i start another activity.
That function is called in the onCreate method of the activity and the problem is that the execution of next instruction continue without waiting the result of my function.
Here is the code :
public class EditAccountActivity extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.edit_account);
save.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
checkConflict();
Log.i("VERIF",
"WE GO HERE WITHOUT WAITING THE RESULT");
//i don't want to go here if we start the other activity in checkConflict
...
}}}
public void checkConflict() {
final Intent intent = new Intent(this, ConflictFieldActivity.class);
new WSDataAccount() {
@Override
public void onPostExecute(final ArrayList<ArrayList<String>> result) {
if (modifiedTimeOnServer > modifiedTimeLocal
&& !conflictWithFields(fieldLocalFirstStateMap,
fieldServerMap.getAccountFieldMap(),
modifiedTimeLocal, modifiedTimeOnServer)
.isEmpty()) {
Toast.makeText(getApplicationContext(),
" EDITION CONFLICT !!!! ", Toast.LENGTH_LONG)
.show();
startActivity(intent);
}
}
}.execute(sessionName, accountId, "retrieveModifiedTime");
}}
Do you know another way to work with the result returned by “onPostExecute”, in order to wait my treatment before executing next instruction
I guess the most simple for you is to call different methods of your Activity, depending on result;
And then