I am trying to activate a runnable after 90 seconds. But if the user leaves the fragment and comes back, when the timer hit, it crashes. Here is what I have so far.
when they click the button:
Handler handler = new Handler();
handler.postDelayed(new RefreshRunnable(this), 1000 * 90);
RefreshRunnable class:
private static class RefreshRunnable extends AsyncTask<String, String, String> implements Runnable {
private WeakReference<GridFragment> mFragmentRef;
private RefreshRunnable(GridFragment fragment) {
mFragmentRef = new WeakReference<GridFragment>(fragment);
}
@Override
public void run() {
this.execute("");
}
@Override
protected String doInBackground(String... params) {
mFragmentRef.get().getLoaderManager().restartLoader(LOADER_ID_GET, null, mFragmentRef.get().mGroupLoaderCallbacks);
return null;
}
}
So in 90 seconds, it is supposed to activate a grid item. It will work if I stay on the fragment the whole 90 seconds. But if i leave and come back, when the 90 seconds hit, it will crash.