Issue
Now I have the following class, which I instantiate in my main activity in order to retrieve some data from the Internet.
As you can see the class contains an AsyncTask which performs the data collection form Internet.
When my activity is paused (via the BACK button on the emulator) I stop the AsyncTask.
Nevertheless LogCat continues to show messages as the AsyncTask is still continuing to try to fetch data from Internet.
Here is the LogCat, it never stops...
12-24 09:36:48.806: E/grabXML(698): java.lang.IllegalStateException: Manager is shut down.
12-24 09:36:48.816: E/grabXML(698): Exception fetching data
12-24 09:36:48.816: E/grabXML(698): java.lang.IllegalStateException: Manager is shut down.
12-24 09:36:48.836: E/grabXML(698): Exception fetching data
12-24 09:36:48.836: E/grabXML(698): java.lang.IllegalStateException: Manager is shut down.
12-24 09:36:48.846: E/grabXML(698): Exception fetching data
12-24 09:36:48.846: E/grabXML(698): java.lang.IllegalStateException: Manager is shut down.
12-24 09:36:48.856: E/grabXML(698): Exception fetching data
12-24 09:36:48.856: E/grabXML(698): java.lang.IllegalStateException: Manager is shut down.
12-24 09:36:48.966: E/grabXML(698): Exception fetching data
12-24 09:36:48.966: E/grabXML(698): java.lang.IllegalStateException: Manager is shut down.
12-24 09:36:48.996: E/grabXML(698): Exception fetching data
12-24 09:36:48.996: E/grabXML(698): java.lang.IllegalStateException: Manager is shut down.
12-24 09:36:49.037: E/grabXML(698): Exception fetching data
12-24 09:36:49.037: E/grabXML(698): java.lang.IllegalStateException: Manager is shut down.
Here is my class
public class Grab{
public String url;
public String srt = "cav";
public boolean flag = false;
public GrabXml g;
public Grab (String u){
url = u;
}
public String vai(){
g = new GrabXml();
g.execute();
Log.e("", srt);
while(!flag){
// nothing
};
g.cancel(true);
return srt;
}
public void fermaGrab() {
g.cancel(true);
}
public class GrabXml extends AsyncTask<Void, String, Void>{
@Override
protected Void doInBackground(Void... arg0) {
Log.e("", "arrivo al do in background");
Log.e("", url);
DefaultHttpClient client = new DefaultHttpClient();
HttpGet getMethod = new HttpGet(url);
try {
ResponseHandler<String> responseHandler = new BasicResponseHandler();
srt = client.execute(getMethod, responseHandler);
Log.e("", "passo per GrabXML");
}
catch (Throwable t) {
android.util.Log.e("grabXML", "Exception fetching data", t);
}
flag = true;
client.getConnectionManager().shutdown();
return null;
}
@Override
protected void onProgressUpdate(String... item) {
// nothing
}
@Override
protected void onPostExecute(Void unused) {
flag = true;
}
}
}
Solution
Found the solution to the riddle: see I continue to receive messages after Activity is destroyed
The Service was actually being killed properly.
The point was that the Service contains an infinite loop, and the loop continued even when the Service was cancelled/destroyed.
Answered By - Lisa Anne
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.