0

My Code:

 userListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

        String userURL = "https://api.github.com/users/" + userNameList.get(position) + "?" + accessToken;
        new JSONTask().execute(userURL);
        Intent intent = new Intent(getActivity(), ProfileActivity.class);
        String key = userNameList.get(position);
        intent.putExtra("userName", key);

        startActivity(intent);

    }
});

This part of my code is a click listener of each item in my list view which is a profile of github users. So, whenever I click an item, it moves to another activity which parses the info from the DB which were stored through

new JSONTask().execute(userURL);

The JSONTask (asyncTask). Moving to the next activity works fine, but when I press the back button, it suddenly stops my app.

It doesn't give me an error when I comment out the JSONTask, but then it won't store the info of the user to the DB.

What could be the problem in this case?

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Dawn17
  • 7,825
  • 16
  • 57
  • 118
  • you probably be calling `getContentResolver` or using db inctance which is no longer aviable 'cuz your activity is no longer alive , hence the crash – Pavneet_Singh Nov 06 '17 at 10:02
  • @Pavneet_Singh Basically, when I call JSONTask, it parses the JSON from the API and stores it into a Firebase DB. In the next Activity, I fetch the data from the DB based on the passed-in "userName". Would that probably be the reason? – Dawn17 Nov 06 '17 at 10:08
  • simply don't let your thread to anything with references in activity when it dies , google `weakrefernce` – Pavneet_Singh Nov 06 '17 at 10:09
  • So, what would be a solution to this? – Dawn17 Nov 06 '17 at 10:17
  • i already have suggested some solution , google them or i would suggest post the whole code with logcat details , your question go for re-opening again , or if it takes too long , delete it re post it – Pavneet_Singh Nov 06 '17 at 13:33

0 Answers0