-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Resolve issues with foreground tasks getting cancelled
- Loading branch information
Showing
19 changed files
with
344 additions
and
181 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
python-for-android/dists/kolibri/src/main/java/org/kivy/android/PythonProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package org.kivy.android; | ||
|
||
import android.content.Context; | ||
|
||
/** | ||
* This class is used to provide the Context to the python-side in a way that minimizes us | ||
* potentially creating memory leaks by holding a static reference to the context. It implements | ||
* AutoCloseable so that it can be used in a try-with-resources block and automatically release | ||
* the static instance and the instance's context. | ||
*/ | ||
public class PythonProvider implements AutoCloseable { | ||
private static final ThreadLocal<PythonProvider> localInstance = new ThreadLocal<>(); | ||
private final Context context; | ||
|
||
public PythonProvider(Context context) { | ||
this.context = context; | ||
localInstance.set(this); | ||
} | ||
|
||
public Context getContext() { | ||
return context; | ||
} | ||
|
||
|
||
public void close() { | ||
localInstance.remove(); | ||
} | ||
|
||
public static PythonProvider create(Context context) { | ||
if (isActive()) { | ||
throw new RuntimeException("PythonProviders cannot be nested"); | ||
} | ||
return new PythonProvider(context); | ||
} | ||
|
||
public static PythonProvider get() { | ||
if (!isActive()) { | ||
throw new RuntimeException("PythonProvider not initialized"); | ||
} | ||
return PythonProvider.localInstance.get(); | ||
} | ||
|
||
public static boolean isActive() { | ||
return localInstance.get() != null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 20 additions & 62 deletions
82
...or-android/dists/kolibri/src/main/java/org/learningequality/Kolibri/ForegroundWorker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 0 additions & 43 deletions
43
...n-for-android/dists/kolibri/src/main/java/org/learningequality/Kolibri/WorkerService.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.