fixes a bug where the app could get stuck in a loop after a crash during recording (the latter should not occur in the first place ^o^).

This commit is contained in:
y20k 2017-05-31 10:30:29 +02:00
parent 5e8c8f215c
commit 576ea43c21
4 changed files with 39 additions and 13 deletions

View file

@ -8,8 +8,8 @@ android {
applicationId "org.y20k.trackbook" applicationId "org.y20k.trackbook"
minSdkVersion 22 minSdkVersion 22
targetSdkVersion 25 targetSdkVersion 25
versionCode 9 versionCode 10
versionName "1.0.2 (Astronomy Domine)" versionName "1.0.3 (Astronomy Domine)"
vectorDrawables.useSupportLibrary = true vectorDrawables.useSupportLibrary = true
} }
buildTypes { buildTypes {
@ -26,5 +26,5 @@ dependencies {
compile 'com.android.support:design:25.3.1' compile 'com.android.support:design:25.3.1'
compile 'com.android.support:cardview-v7:25.3.1' compile 'com.android.support:cardview-v7:25.3.1'
compile 'org.osmdroid:osmdroid-android:5.6.4' compile 'org.osmdroid:osmdroid-android:5.6.4'
compile 'com.google.code.gson:gson:2.8.0' compile 'com.google.code.gson:gson:2.8.1'
} }

View file

@ -28,6 +28,7 @@ import android.content.pm.PackageManager;
import android.location.Location; import android.location.Location;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.os.Environment;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
@ -92,6 +93,9 @@ public class MainActivity extends AppCompatActivity implements TrackbookKeys {
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
// check state of External Storage
checkExternalStorageState();
// load saved state of app // load saved state of app
loadFloatingActionButtonState(this); loadFloatingActionButtonState(this);
@ -655,6 +659,24 @@ public class MainActivity extends AppCompatActivity implements TrackbookKeys {
} }
/* Checks the state of External Storage */
private void checkExternalStorageState() {
String state = Environment.getExternalStorageState();
if (!state.equals(Environment.MEDIA_MOUNTED)) {
LogHelper.e(LOG_TAG, "Error: Unable to mount External Storage. Current state: " + state);
// move MainActivity to back
moveTaskToBack(true);
// shutting down app
android.os.Process.killProcess(android.os.Process.myPid());
System.exit(1);
}
}
/** /**
* Inner class: SectionsPagerAdapter that returns a fragment corresponding to one of the tabs. * Inner class: SectionsPagerAdapter that returns a fragment corresponding to one of the tabs.
* see also: https://developer.android.com/reference/android/support/v4/app/FragmentPagerAdapter.html * see also: https://developer.android.com/reference/android/support/v4/app/FragmentPagerAdapter.html

View file

@ -129,7 +129,9 @@ public class TrackerService extends Service implements TrackbookKeys, SensorEven
// ACTION STOP // ACTION STOP
else if (intent.getAction().equals(ACTION_STOP) || !mLocationSystemSetting) { else if (intent.getAction().equals(ACTION_STOP) || !mLocationSystemSetting) {
stopTracking(); if (mTrack != null) {
stopTracking();
}
// save changed state of Floating Action Button // save changed state of Floating Action Button
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this.getApplicationContext()); SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this.getApplicationContext());
@ -413,7 +415,9 @@ public class TrackerService extends Service implements TrackbookKeys, SensorEven
mLocationSystemSetting = LocationHelper.checkLocationSystemSetting(getApplicationContext()); mLocationSystemSetting = LocationHelper.checkLocationSystemSetting(getApplicationContext());
if (previousLocationSystemSetting != mLocationSystemSetting && !mLocationSystemSetting && mTrackerServiceRunning) { if (previousLocationSystemSetting != mLocationSystemSetting && !mLocationSystemSetting && mTrackerServiceRunning) {
LogHelper.v(LOG_TAG, "Location Setting turned off while tracking service running."); LogHelper.v(LOG_TAG, "Location Setting turned off while tracking service running.");
stopTracking(); if (mTrack != null) {
stopTracking();
}
stopForeground(true); stopForeground(true);
} }
} }

View file

@ -51,18 +51,18 @@ public class StorageHelper implements TrackbookKeys {
private static final String LOG_TAG = StorageHelper.class.getSimpleName(); private static final String LOG_TAG = StorageHelper.class.getSimpleName();
/* Main class variables */ /* Main class variables */
private final Context mActivity; private final Context mContext;
private File mFolder; private File mFolder;
private final File mTempFile; private final File mTempFile;
/* Constructor */ /* Constructor */
public StorageHelper(Context activity) { public StorageHelper(Context context) {
// store activity // store activity
mActivity = activity; mContext = context;
// get "tracks" folder // get "tracks" folder
mFolder = mActivity.getExternalFilesDir(TRACKS_DIRECTORY_NAME); mFolder = mContext.getExternalFilesDir(TRACKS_DIRECTORY_NAME);
// mFolder = getTracksDirectory(); // mFolder = getTracksDirectory();
// create "tracks" folder if necessary // create "tracks" folder if necessary
@ -129,7 +129,7 @@ public class StorageHelper implements TrackbookKeys {
// if write was successful delete old track files - only if not a temp file // if write was successful delete old track files - only if not a temp file
if (fileType != FILE_TEMP_TRACK) { if (fileType != FILE_TEMP_TRACK) {
// include temp file if it exists // include temp file if it exists
deleteOldTracks(true); deleteOldTracks(true);
} }
@ -340,9 +340,9 @@ public class StorageHelper implements TrackbookKeys {
} }
/* Return a write-able sub-directory from external storage */ /* Return a write-able sub-directory from external storage */
private File getTracksDirectory() { private File getTracksDirectory() {
File[] storage = mActivity.getExternalFilesDirs(TRACKS_DIRECTORY_NAME); File[] storage = mContext.getExternalFilesDirs(TRACKS_DIRECTORY_NAME);
for (File file : storage) { for (File file : storage) {
if (file != null) { if (file != null) {
String state = EnvironmentCompat.getStorageState(file); String state = EnvironmentCompat.getStorageState(file);
@ -352,7 +352,7 @@ public class StorageHelper implements TrackbookKeys {
} }
} }
} }
Toast.makeText(mActivity, R.string.toast_message_no_external_storage, Toast.LENGTH_LONG).show(); Toast.makeText(mContext, R.string.toast_message_no_external_storage, Toast.LENGTH_LONG).show();
LogHelper.e(LOG_TAG, "Unable to access external storage."); LogHelper.e(LOG_TAG, "Unable to access external storage.");
return null; return null;