Skip to content
This repository was archived by the owner on Aug 26, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,14 @@
*/
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion '25.0.1'
compileSdkVersion 29
defaultConfig {
applicationId 'de.stocard.keepactivitiestile'
minSdkVersion 24
targetSdkVersion 25
targetSdkVersion 29
versionCode 1
versionName "1.0"
archivesBaseName = "keep-activities-qs"
jackOptions {
enabled true
}
}

buildTypes {
Expand All @@ -41,5 +37,5 @@ android {
}
}
dependencies {
compile 'com.android.support:support-annotations:25.0.1'
api 'androidx.annotation:annotation:1.1.0'
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

compile has been replaced by implementation
api is useful when you want to expose class and symbols to another module.
Here this is useless.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, didn't notice that migration to AndroidX automatically used api.

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,18 @@

import android.content.ContentResolver;
import android.content.Context;
import android.os.Build;
import android.provider.Settings;
import android.support.annotation.DrawableRes;
import android.support.annotation.NonNull;
import android.support.annotation.StringRes;
import android.util.Log;
import android.widget.Toast;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

import androidx.annotation.DrawableRes;
import androidx.annotation.NonNull;
import androidx.annotation.StringRes;

/**
* A helper class for working with the system setting for "Don't keep activities".
* <p>
Expand Down Expand Up @@ -85,7 +87,7 @@ static boolean setKeepActivities(@NonNull Context context, boolean keepActivitie
} catch (SecurityException | NoSuchMethodException | IllegalAccessException | InvocationTargetException | ClassNotFoundException e) {
String message = context.getString(R.string.permission_required_toast);
Toast.makeText(context.getApplicationContext(), message, Toast.LENGTH_LONG).show();
Log.d(TAG, message);
Log.e(TAG, message, e);
return false;
}
}
Expand All @@ -94,12 +96,21 @@ private static void setKeepActivitiesInActivityManager(
boolean keepActivities) throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException {
// Due to restrictions related to hidden APIs, need to emulate the line below
// using reflection:
// ActivityManagerNative.getDefault().setAlwaysFinish(keepActivities);
final Class classActivityManagerNative = Class.forName("android.app.ActivityManagerNative");
final Method methodGetDefault = classActivityManagerNative.getMethod("getDefault");
final Method methodSetAlwaysFinish = classActivityManagerNative.getMethod("setAlwaysFinish", new Class[]{boolean.class});
final Object objectInstance = methodGetDefault.invoke(null);
methodSetAlwaysFinish.invoke(objectInstance, new Object[]{!keepActivities});
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
// ActivityManagerNative.getDefault().setAlwaysFinish(keepActivities);
final Class classActivityManagerNative = Class.forName("android.app.ActivityManagerNative");
final Method methodGetDefault = classActivityManagerNative.getMethod("getDefault");
final Method methodSetAlwaysFinish = classActivityManagerNative.getMethod("setAlwaysFinish", new Class[]{boolean.class});
final Object objectInstance = methodGetDefault.invoke(null);
methodSetAlwaysFinish.invoke(objectInstance, new Object[]{!keepActivities});
} else {
// ActivityManager.getService().setAlwaysFinish(keepActivities);
final Class classActivityManager = Class.forName("android.app.ActivityManager");
final Method methodGetService = classActivityManager.getMethod("getService");
final Object serviceInstance = methodGetService.invoke(null);
final Method methodSetAlwaysFinish = serviceInstance.getClass().getMethod("setAlwaysFinish", new Class[]{boolean.class});
methodSetAlwaysFinish.invoke(serviceInstance, new Object[]{!keepActivities});
}
}

private static void storeSetting(@NonNull Context context, boolean keepActivities) {
Expand Down
4 changes: 3 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
classpath 'com.android.tools.build:gradle:3.5.3'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand All @@ -29,6 +30,7 @@ buildscript {
allprojects {
repositories {
jcenter()
google()
}
}

Expand Down
2 changes: 2 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
android.enableJetifier=true
android.useAndroidX=true
org.gradle.jvmargs=-Xmx1536m

# When configured, Gradle will run in incubating parallel mode.
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Fri Sep 02 10:49:19 BST 2016
#Tue Jan 28 19:31:47 CET 2020
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think, you should run the following command:
./gradlew wrapper --gradle-version=5.4.1 --distribution-type=all, it will update:

  • gradlew
  • gradlew.bat
  • ...

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. If I remember correctly, this was no longer updating anything around gradle version 4 and 5, but there were a lot of changes since v2.14.