I tried AsyncTask
, Thread and Handler but i don't get it.
The method readXML()
takes about 1-2 minutes and i only need a way to cancel this operation. All the solutions I've found were for short time operations (set flag, check flag and break).
Edit
protected class InitTask extends AsyncTask<Context, Integer, String> {
@Override
protected String doInBackground( Context... params ){
try{
preparing = true;
readXML();
preparing = false;
} catch( Exception e ){
Log.i("test", e.getMessage() );
}
return "COMPLETE!";
}
@Override
protected void onCancelled(){
super.onCancelled();
}
}
// ....
_initTask = new InitTask();
_initTask.execute(this);
// ....
_initTask.cancel(true);