disable refreshing when activity is paused

This commit is contained in:
Andrew Dolgov 2011-11-29 07:12:43 +03:00
parent 9a4c7a2ce8
commit 02cd3703bc
2 changed files with 21 additions and 12 deletions

View File

@ -14,7 +14,6 @@ import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.os.Bundle; import android.os.Bundle;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
@ -28,7 +27,6 @@ import android.widget.TextView;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.JsonArray; import com.google.gson.JsonArray;
import com.google.gson.JsonElement; import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.reflect.TypeToken; import com.google.gson.reflect.TypeToken;
public class FeedCategoriesFragment extends Fragment implements OnItemClickListener, OnSharedPreferenceChangeListener { public class FeedCategoriesFragment extends Fragment implements OnItemClickListener, OnSharedPreferenceChangeListener {

View File

@ -315,23 +315,18 @@ public class MainActivity extends FragmentActivity implements FeedsFragment.OnFe
Intent refresh = new Intent(this, MainActivity.class); Intent refresh = new Intent(this, MainActivity.class);
startActivity(refresh); startActivity(refresh);
finish(); finish();
} else if (m_sessionId != null) {
m_refreshTask = new RefreshTask();
m_refreshTimer = new Timer("Refresh");
m_refreshTimer.schedule(m_refreshTask, 60*1000L, 120*1000L);
} }
} }
@Override @Override
public void onDestroy() { public void onDestroy() {
super.onDestroy(); super.onDestroy();
if (m_refreshTask != null) {
m_refreshTask.cancel();
m_refreshTask = null;
}
if (m_refreshTimer != null) {
m_refreshTimer.cancel();
m_refreshTimer = null;
}
} }
@Override @Override
@ -603,6 +598,22 @@ public class MainActivity extends FragmentActivity implements FeedsFragment.OnFe
} }
} }
@Override
public void onPause() {
super.onPause();
if (m_refreshTask != null) {
m_refreshTask.cancel();
m_refreshTask = null;
}
if (m_refreshTimer != null) {
m_refreshTimer.cancel();
m_refreshTimer = null;
}
}
private void loginSuccess() { private void loginSuccess() {
findViewById(R.id.loading_container).setVisibility(View.INVISIBLE); findViewById(R.id.loading_container).setVisibility(View.INVISIBLE);
findViewById(R.id.main).setVisibility(View.VISIBLE); findViewById(R.id.main).setVisibility(View.VISIBLE);