src/main/java/de/blau/android/util/SavingHelper.java
/**
     * Serializes the given object and writes it to a private file with the given name
     * 
     * Original version was running out of stack, fixed by moving to a thread
     * 
     * @param context Android Context
     * @param filename filename of the save file
     * @param object object to save
     * @param compress true if the output should be gzip-compressed, false if it should be written without compression
     * @return true if successful, false if saving failed for some reason
     * @param jdk use the built-in serialisation if true
     */
Serializes the given object and writes it to a private file with the given name

Original version was running out of stack, fixed by moving to a thread


Serializes the given object and writes it to a private file with the given name Original version was running out of stack fixed by moving to a thread
public synchronized boolean save(@NonNull Context context, @NonNull String filename, @NonNull T object, boolean compress, boolean jdk) {
        try {
            Log.d(DEBUG_TAG, "preparing to save " + filename);
            SaveThread r = new SaveThread(context, filename, object, compress, jdk);
            Thread t = new Thread(null, r, SaveThread.DEBUG_TAG, stackSize);
            t.start();
            t.join(60000); 
            Log.d(DEBUG_TAG, "save thread finished");
            return r.getResult();
        } catch (Exception e) { 
            ACRAHelper.nocrashReport(e, e.getMessage());
            return false;
        }
    }
public synchronized boolean save ( @ NonNull Context context , @ NonNull String filename , @ NonNull T object , boolean compress , boolean jdk ) { try { Log . d ( DEBUG_TAG , "preparing to save " + filename ) ; SaveThread r = new SaveThread ( context , filename , object , compress , jdk ) ; Thread t = new Thread ( null , r , SaveThread . DEBUG_TAG , stackSize ) ; t . start ( ) ; t . join ( 60000 ) ; Log . d ( DEBUG_TAG , "save thread finished" ) ; return r . getResult ( ) ; } catch ( Exception e ) { ACRAHelper . nocrashReport ( e , e . getMessage ( ) ) ; return false ; } }
Serializes the given object and writes it to a private file with the given name
Serializes the given object and writes it to a private file with the given name
// wait max 60 s for thread to finish TODO this needs to be done differently given this // limits the size of the file that can be saved // NOSONAR