0

I'm developing an app using Swipe tab that contains 2 fragment. I have an AsyncTaskLoader in Fragment 1 to load data from database and display in a ListView, an AsyncTask in Fragment 2 to parse JSON data from server and display in a ListView too. It seems work fine but sometimes I got crash because of window leak blah blah. The question is how to make the AsyncTask in Fragment 2 only run when I swipe into it? Now, when I start my app, the AsyncTask runs even I'm in Fragment 1.

Thanks

Minh Phan
  • 47
  • 6

2 Answers2

0

You can try this(on second fragment):

@Override
    public void setMenuVisibility(final boolean visible) {
        super.setMenuVisibility(visible);
        if((visible)  )
        {
             //do something here    
        }

      }
CompEng
  • 7,161
  • 16
  • 68
  • 122
0

Be more specific please. If you can post your code.

your error is something lie this?

Activity has leaked window that was originally added

if it is, it means you have showed a progress dialog in a AsyncTask and hidded it after the OnPostExecuted() method, but you forget to dissmis() that progressdialog

check out this post

Activity has leaked window that was originally added

Community
  • 1
  • 1
UrielUVD
  • 482
  • 1
  • 9
  • 27
  • I already have dialog.dismiss() at onPostExecute, It occurred randomly so I'm afraid it's because of the Loader in Fragment 1. I'm now away from my computer so I'll post my code later – Minh Phan Apr 18 '14 at 06:57