Skip to content

Instantly share code, notes, and snippets.

View npace's full-sized avatar

Lubomir Naydenov npace

View GitHub Profile
@npace
npace / debug_non-test-only_build.gradle
Created October 30, 2017 16:13
Override android:testOnly being set to "true" in a debug APK's AndroidManifest by the Android Gradle plugin v. 3.0.0
...
android {
...
// Override the android:testOnly="true" attribute that the new build tools set so that debug APKs can be installed normally
applicationVariants.all { variant ->
variant.outputs.all { output ->
output.processManifest.doLast {
String manifestPath = "$manifestOutputDirectory/AndroidManifest.xml"
def manifestContent = file(manifestPath).getText()
manifestContent = manifestContent.replace('android:testOnly="true"', 'android:testOnly="false"')
@npace
npace / ForegroundLifecycleCallback.java
Created April 5, 2017 12:11
Simple implementation of ActivityLifecycleCallbacks that determines whether the app is currently in the foreground
// package declaration, imports...
public class ForegroundLifecycleCallback implements Application.ActivityLifecycleCallbacks {
private int startedActivitiesCount = 0;
@Override
public void onActivityStarted(Activity activity) {
if (startedActivitiesCount == 0) {
// your foreground stuff
}