Only do background updates when the main activities are not in the foreground
This commit is contained in:
parent
6b0a1db687
commit
4f864aaf10
@ -2,7 +2,8 @@
|
|||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
package="org.fdroid.fdroid" android:versionCode="4"
|
package="org.fdroid.fdroid" android:versionCode="4"
|
||||||
android:versionName="0.13" android:installLocation="auto">
|
android:versionName="0.13" android:installLocation="auto">
|
||||||
<application android:label="@string/app_name" android:icon="@drawable/icon">
|
<application android:name="FDroidApp" android:label="@string/app_name"
|
||||||
|
android:icon="@drawable/icon">
|
||||||
<uses-sdk android:minSdkVersion="3" />
|
<uses-sdk android:minSdkVersion="3" />
|
||||||
|
|
||||||
<activity android:name="FDroid">
|
<activity android:name="FDroid">
|
||||||
@ -29,6 +30,6 @@
|
|||||||
|
|
||||||
<uses-permission android:name="android.permission.INTERNET" />
|
<uses-permission android:name="android.permission.INTERNET" />
|
||||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||||
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
|
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
|
||||||
|
|
||||||
</manifest>
|
</manifest>
|
||||||
|
@ -170,13 +170,19 @@ public class AppDetails extends ListActivity {
|
|||||||
@Override
|
@Override
|
||||||
protected void onStart() {
|
protected void onStart() {
|
||||||
super.onStart();
|
super.onStart();
|
||||||
|
((FDroidApp) getApplication()).inActivity++;
|
||||||
// Get the preferences we're going to use in this Activity...
|
// Get the preferences we're going to use in this Activity...
|
||||||
SharedPreferences prefs = PreferenceManager
|
SharedPreferences prefs = PreferenceManager
|
||||||
.getDefaultSharedPreferences(getBaseContext());
|
.getDefaultSharedPreferences(getBaseContext());
|
||||||
pref_cacheDownloaded = prefs.getBoolean("cacheDownloaded", true);
|
pref_cacheDownloaded = prefs.getBoolean("cacheDownloaded", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onStop() {
|
||||||
|
((FDroidApp) getApplication()).inActivity--;
|
||||||
|
super.onStop();
|
||||||
|
}
|
||||||
|
|
||||||
// Reset the display and list contents. Used when entering the activity, and
|
// Reset the display and list contents. Used when entering the activity, and
|
||||||
// also when something has been installed/uninstalled. In the latter case,
|
// also when something has been installed/uninstalled. In the latter case,
|
||||||
// 'update' is true to make the installed status get refreshed.
|
// 'update' is true to make the installed status get refreshed.
|
||||||
@ -381,7 +387,7 @@ public class AppDetails extends ListActivity {
|
|||||||
msg.arg2 = 1;
|
msg.arg2 = 1;
|
||||||
msg.obj = new String(localfile);
|
msg.obj = new String(localfile);
|
||||||
download_handler.sendMessage(msg);
|
download_handler.sendMessage(msg);
|
||||||
msg=new Message();
|
msg = new Message();
|
||||||
msg.arg1 = 1;
|
msg.arg1 = 1;
|
||||||
download_handler.sendMessage(msg);
|
download_handler.sendMessage(msg);
|
||||||
} else {
|
} else {
|
||||||
@ -526,9 +532,10 @@ public class AppDetails extends ListActivity {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||||
if(requestCode==REQUEST_INSTALL) {
|
if (requestCode == REQUEST_INSTALL) {
|
||||||
// If we're not meant to be caching, delete the apk file we just
|
// If we're not meant to be caching, delete the apk file we just
|
||||||
// installed (or maybe the user cancelled the install - doesn't matter)
|
// installed (or maybe the user cancelled the install - doesn't
|
||||||
|
// matter)
|
||||||
// from the SD card...
|
// from the SD card...
|
||||||
if (!pref_cacheDownloaded) {
|
if (!pref_cacheDownloaded) {
|
||||||
String apkname = curapk.apkName;
|
String apkname = curapk.apkName;
|
||||||
|
@ -192,9 +192,16 @@ public class FDroid extends TabActivity implements OnItemClickListener {
|
|||||||
@Override
|
@Override
|
||||||
protected void onStart() {
|
protected void onStart() {
|
||||||
super.onStart();
|
super.onStart();
|
||||||
|
((FDroidApp) getApplication()).inActivity++;
|
||||||
populateLists(true);
|
populateLists(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onStop() {
|
||||||
|
((FDroidApp) getApplication()).inActivity--;
|
||||||
|
super.onStop();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCreateOptionsMenu(Menu menu) {
|
public boolean onCreateOptionsMenu(Menu menu) {
|
||||||
|
|
||||||
@ -300,6 +307,7 @@ public class FDroid extends TabActivity implements OnItemClickListener {
|
|||||||
// service accordingly. It's cheap, so no need to check if the particular setting has
|
// service accordingly. It's cheap, so no need to check if the particular setting has
|
||||||
// actually been changed.
|
// actually been changed.
|
||||||
UpdateService.schedule(getBaseContext());
|
UpdateService.schedule(getBaseContext());
|
||||||
|
populateLists(false);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -76,6 +76,12 @@ public class UpdateService extends Service {
|
|||||||
new Thread() {
|
new Thread() {
|
||||||
public void run() {
|
public void run() {
|
||||||
|
|
||||||
|
// If we're in one of our list activities, we don't want
|
||||||
|
// to run an update because the database will be out of
|
||||||
|
// sync with the display.
|
||||||
|
if (((FDroidApp) getApplication()).inActivity != 0)
|
||||||
|
return;
|
||||||
|
|
||||||
// See if it's time to actually do anything yet...
|
// See if it's time to actually do anything yet...
|
||||||
SharedPreferences prefs = PreferenceManager
|
SharedPreferences prefs = PreferenceManager
|
||||||
.getDefaultSharedPreferences(getBaseContext());
|
.getDefaultSharedPreferences(getBaseContext());
|
||||||
@ -99,8 +105,9 @@ public class UpdateService extends Service {
|
|||||||
try {
|
try {
|
||||||
db = new DB(getBaseContext());
|
db = new DB(getBaseContext());
|
||||||
RepoXMLHandler.doUpdates(db);
|
RepoXMLHandler.doUpdates(db);
|
||||||
} catch(Exception e) {
|
} catch (Exception e) {
|
||||||
Log.d("FDroid","Exception during handleCommand() - " + e.getMessage());
|
Log.d("FDroid", "Exception during handleCommand() - "
|
||||||
|
+ e.getMessage());
|
||||||
} finally {
|
} finally {
|
||||||
if (db != null)
|
if (db != null)
|
||||||
db.close();
|
db.close();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user