Resolved a crash, under some circumstances, after installing an app and returning

This commit is contained in:
Ciaran Gultnieks 2010-12-09 10:57:28 +00:00
parent b9a41878f8
commit 38fc4bfec1
2 changed files with 20 additions and 9 deletions

View File

@ -162,6 +162,7 @@ public class AppDetails extends ListActivity {
} }
private boolean pref_cacheDownloaded; private boolean pref_cacheDownloaded;
private boolean viewResetRequired;
@Override @Override
protected void onStart() { protected void onStart() {
@ -173,24 +174,33 @@ public class AppDetails extends ListActivity {
SharedPreferences prefs = PreferenceManager SharedPreferences prefs = PreferenceManager
.getDefaultSharedPreferences(getBaseContext()); .getDefaultSharedPreferences(getBaseContext());
pref_cacheDownloaded = prefs.getBoolean("cacheDownloaded", true); pref_cacheDownloaded = prefs.getBoolean("cacheDownloaded", true);
viewResetRequired = true;
reset(false); }
@Override
protected void onResume() {
if (viewResetRequired) {
reset();
viewResetRequired = false;
}
super.onResume();
} }
@Override @Override
protected void onStop() { protected void onStop() {
db.close(); db.close();
db = null;
((FDroidApp) getApplication()).inActivity--; ((FDroidApp) getApplication()).inActivity--;
super.onStop(); 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.
// 'update' is true to make the installed status get refreshed. private void reset() {
private void reset(boolean update) {
Log.d("FDroid", "Getting application details for " + appid); Log.d("FDroid", "Getting application details for " + appid);
app = db.getApps(appid, null, update).get(0); app = db.getApps(appid, null, true).get(0);
DB.Apk curver = app.getCurrentVersion(); DB.Apk curver = app.getCurrentVersion();
app_currentvercode = curver == null ? 0 : curver.vercode; app_currentvercode = curver == null ? 0 : curver.vercode;
@ -540,6 +550,7 @@ 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 // installed (or maybe the user cancelled the install - doesn't
@ -551,9 +562,10 @@ public class AppDetails extends ListActivity {
File file = new File(apk_file); File file = new File(apk_file);
file.delete(); file.delete();
} }
viewResetRequired = true;
} }
reset(true);
} }
} }

View File

@ -347,9 +347,9 @@ public class DB {
// version is older than the current one. // version is older than the current one.
for (App app : result) { for (App app : result) {
Apk curver = app.getCurrentVersion(); Apk curver = app.getCurrentVersion();
if (curver!= null && app.installedVersion != null if (curver != null && app.installedVersion != null
&& !app.installedVersion.equals(curver.version)) { && !app.installedVersion.equals(curver.version)) {
if(app.installedVerCode < curver.vercode) if (app.installedVerCode < curver.vercode)
app.hasUpdates = true; app.hasUpdates = true;
} }
} }
@ -363,7 +363,6 @@ public class DB {
Map<String, PackageInfo> systemApks = new HashMap<String, PackageInfo>(); Map<String, PackageInfo> systemApks = new HashMap<String, PackageInfo>();
Log.d("FDroid", "Reading installed packages"); Log.d("FDroid", "Reading installed packages");
for (PackageInfo appInfo : installedPackages) { for (PackageInfo appInfo : installedPackages) {
Log.d("FDroid", "... " + appInfo.packageName);
systemApks.put(appInfo.packageName, appInfo); systemApks.put(appInfo.packageName, appInfo);
} }