Force close when press back while fetching data from internet
<p>Whenever user press back  button While fetching xml data from web using AsyncTask my app goes to force close state. How can i solve this. Thanks in advance. </p>

<pre><code>public class InboxActivity extends Activity {
public static ExpandableListView mailList;
List&lt;HashMap&lt;String,String&gt;&gt; list;
MailList asyncTaskMailList;
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.inbox_layout);
    ConstantValues.footerCurrentActivity=InboxActivity.this;
    mailList=(ExpandableListView)findViewById(R.id.expandableListView1);
    HomePageActivity.homePageTabHost.getTabWidget().getChildTabViewAt(ConstantValues.CURRENT_POSITION)
        .setBackgroundDrawable(getResources().getDrawable(R.drawable.tab_widget_normal));
    asyncTaskMailList=new MailList();
    asyncTaskMailList.execute();
}
private OnChildClickListener childClickListener=new ExpandableListView.OnChildClickListener() {
    public boolean onChildClick(ExpandableListView parent, View v,int groupPosition, int childPosition, long id) {
        ConstantValues.STATION_NAME=ConstantValues.inboxStations.get(groupPosition);
        ConstantValues.CURRENT_POSITION=1;
        startActivity(new Intent(InboxActivity.this, HomePageActivity.class));
        return false;
    }
};
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if(keyCode == KeyEvent.KEYCODE_BACK){
        this.getParent().onBackPressed();
        asyncTaskMailList.cancel(true);
        return true;
    }
    return super.onKeyDown(keyCode, event);
}
@Override
protected void onStop() {
    super.onStop();
    asyncTaskMailList.cancel(true);
}
@Override
protected void onDestroy() {
    asyncTaskMailList.cancel(true);
    super.onDestroy();
}
class MailList extends AsyncTask&lt;String, String, String&gt;
{
    @Override
    protected void onPreExecute() {
        super.onPreExecute();
        NetworkExceptionPopUp.showProgressBar();
    }
    @Override
    protected String doInBackground(String... params) {
        list=new ArrayList&lt;HashMap&lt;String,String&gt;&gt;();
        WebServerCall.getInboxMail(InboxActivity.this);
        return null;
    }
    @Override
    protected void onPostExecute(String result) {
        super.onPostExecute(result);
        mailList.setAdapter(new InboxAdapter(InboxActivity.this));
        NetworkExceptionPopUp.dismissProgressBar();
        mailList.setOnGroupClickListener(null);
        mailList.setOnChildClickListener(childClickListener);
        mailList.setClickable(true);

    }
}
</code></pre>

<p>}
    Above code is my updated code. This also sometime shows exception. Here, I had used onStop() and OnDestroy() to cancel AsyncTask while other activity comes top.</p>
